.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

SQLCMD Miscellaneous Commands :r

Posted By:      Posted Date: October 13, 2010    Points: 0   Category :Sql Server

I have a batch file that executes Test.sql. In Test.sql I have following sql statements.

The question is can I pass parameters to the SQL script that I am calling using command ":r".

--Test.sql file contains this script 






:On Error exit

:r c:\Scripts\CREATE_TABLES.sql [parameters...]


View Complete Post

More Related Resource Links

Consecutive SQL sqlcmd GO commands


What happens when a sqlcmd GO command is followed by another GO command?  Here's an example:



sp_extendedproperty N'_database_tools_support', N'log', N'schema', N'dbo', N'table', N'__RefactorLog'




ASP.Net Gridview Edit Update Cancel Commands

In ASP.Net 2.0, GridView Control also provides the functionality to edit and update the data retrieved from the database using CommandField template. You can cancel the action using Cancel Command of the CommandField. GridView consists of events that can be used to perform the actions like edit, update and cancel upon the Data items displayed in the ASP.Net GridView Data Control.

Advanced WPF: Understanding Routed Events And Commands In WPF


See how routed events and routed commands in Windows Presentation Foundation form the basis for communication between the parts of your UI.

Brian Noyes

MSDN Magazine September 2008

Cmdlets: Extend Windows PowerShell With Custom Commands


Jim Truher presents an introduction to writing and registering your own custom cmdlets to be used in Windows PowerShell.

Jim Truher

MSDN Magazine December 2007

.NET Reflection: Dynamically Bind Your Data Layer to Stored Procedures and SQL Commands Using .NET M


One major inconvenience of using SQL stored procedures from code is having to match type information. You have to write long wrapper functions around the procedures just to expose the data types. In the .NET Framework, however, the reflection services of the System.Reflection namespace allow you to query rich metadata that describe data types. This article explains how to use reflection in .NET to end your stored procedure nightmares. The author creates four custom classes, including one that generates a SQLCommand object based on the metadata of a method. Using this library, you'll be on your way to automating the generation of stored procedures.

Atif Aziz

MSDN Magazine August 2002

SQLCMD: supress "Changed database context to . . ."

Product:  2008 SQL Server Standard Edition. Shell:     SQLCMD (i.e. sqlcmd -i"test.sql")Script (test.sql):   use Master;   print $(SQLCMDERRORLEVEL)The screen output is always:   Changed database context to 'Master'   0However I want the above output to be (only):   0I have tried calling SQLCMD with the -m command line parameter set to each of the {-m-1, -m 0, -m 1} settings, but none work. I have tried: set SQLCMDERRORLEVEL = each of {-1,0,1,25), but none workAnybody know the secret?Thanks in advance,Jerry

SQLCMD: Changed Database Context messages

Is there a way to suppress the "Changed Database Context to " messages in SQLCMD?  For example, I get the following: 1> use master2> goChanged database context to 'master'.1>I am trying to migrate some legacy batch files that called isql and used the output files.  These extra "Changed Database Context to " messages are causing our scripts to break, and I was hoping to avoid having to write something extra to handle these messages.Thanks.

sqlcmd, cannot connect to server

I have SQL Server installed on a machine called SQLDEV. I log on to that machine and I run the command sqlcmd -s SQLDEV -Q "select * from <db>.<schema>.<some_table> -E This command works and returns a result set.   Next, I go to a different machine. On that machine I can use SQL Mgmt Studio to log on to SQLDEV using window authentication. However, if I run the same command as above, I get some kind of a connection error. The error says, ".... When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections .....   Any suggestions/ideas why I am getting this error?

Selecting Particular Commands with sp_repldone

Is it possible to use sp_repldone to mark all commands distributed up to a certain point? We have a scenario where the log reader is unable to construct a command from one problematic command. Log Reader Agent failed to construct a replicated command from log sequence number (LSN) {0000fc2c:000afd81:0009}. Back up the publication database and contact Customer Support Services. (Source: MSSQLServer, Error number: 18805) In order to correct this problem we issue the following: EXEC sp_repldone @xactid = NULL, @xact_segno = NULL, @numtrans = 0, @time = 0, @reset = 1 EXEC sp_replflush GO Unfortunately, this marks all commands as being distributed, even the commands that occurred after the problematic one.  From BOL it seems as though it’s possible to mark the problematic command and all earlier commands as distributed. (With sp_repldone, you can manually tell the server that a transaction has been replicated (sent to the Distributor). It also allows you to change the transaction marked as the next one awaiting replication. You can move forward or backward in the list of replicated transactions. (All transactions less than or equal to that transaction are marked as distributed.)) Does anyone know how to do this? I found an interesting article which discusses this but it’s from 2003 so I’m reluctant to rely on it in a production system. http://www

A FocusScope Nightmare (Bug?): Commands Are Disabled

I've got a simple menu with some simple commands:   Code Snippet <Menu> <MenuItem Header="Edit"> <MenuItem Command="ApplicationCommands.Cut" /> <MenuItem Command="ApplicationCommands.Copy" /> </MenuItem> </Menu>     I've got a simple control:   Code Snippet <UserControl x:Class="WpfApplication2.UserControlRed" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Grid /> </UserControl>     The code-behind for this control enables handling the 'Cut' command: Code Snippet   public partial class UserControlRed : UserControl { public UserControlRed() { InitializeComponent(); this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, this.OnCut, this.OnAlwaysExecute)); } public void OnCut(object sender, RoutedEventArgs routedEventArgs) { Console.WriteLine("Cut"); } private void OnAlwaysExecute(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = true; } }     This control is added to a simple page so it can be navigated to using a Frame:   Code Snippet <!-- The Menu Commands are enabed with this code. --> <Page x:Class="WpfApplication2.PageRed" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x=&

Drag and Drop Events binded to MVVM commands

Hi , I am developing the drag n drop functionality.. I want in my drop event my command from MVVM model should fire.. Can you help me in how to Map Drag drop events  into MVVM by Commands...

messages from sqlcmd

Would someone please explain this behavior? I'm trying to understand why the messages are coming back the way they are in the following examples. Create a simple table to which we will be inserting some values. create table test_table ( col1 int ) Next, create a sql script that inserts a bunch of integers to the above table. insert into test_table values(1) insert into test_table_ values(2) insert into test_table_ values(3) insert into test_table_ values(4) And save this file. I saved it as c:\dba\admin\test_script.sql Next, run this script from a command window using sqlcmd as follows. sqlcmd -S <your_server> -d <your_db> -i c:\dba\admin\test_script.sql   What message do you get back in the command window? I get "(1 rows affected)" for the first insert statement in the script, but nothing about the other 3 inserts. However, when I select from the table, I do see that all 4 insert statments happened. So, why am I seeing an incomplete message? Now, for the heck of it, I put a "GO" between the insert statements in test_script.sql like so. insert into test_table values(1) go insert into test_table values(2) go insert into test_table values(3) go insert into test_table values(4) Now, run the sqlcmd again like so, sqlcmd -S <your_server> -d <your_db> -i c:\dba\admin\test_script.sql What messages do you get? I get 4 lines of

WPF, MVVM, Commands from buttons within a Listbox ItemTemplate? (code included)

I want to capture button clicks from within a list item row. Below I have tried to boil the problem down as much as I can. First, here is the xaml <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="test2.MainWindow" x:Name="Window" Title="MainWindow">  <Grid x:Name="LayoutRoot">  <ListView Margin="148,74,0,202" HorizontalAlignment="Left" ItemsSource="{Binding ListData}">   <ListView.View>    <GridView>     <GridViewColumn Header="Item" DisplayMemberBinding="{Binding ItemName}" />     <GridViewColumn Header="Options" Width="200" >      <GridViewColumn.CellTemplate>       <DataTemplate>        <StackPanel Orientation="Horizontal">         <Button Content="Reject" Height="20" Width="80" Margin="5,2" Command="{Binding Commands}" CommandParameter="RejectItem" /> 

Deactivate WPF commands globally (class registered)

Hello everyone, I need to deactivate the default WPF commands in a globally way, i'm talking about those that are registered as "class commands". Here's the reason : We are upgrading an old application to WPF, that application uses some key shortcuts that overlap with default wpf commands. I know that that should be a problem as commands attached to an instance have more "priority" than those that are attached to the "type" or "class". The problem is, we cannot attach the input binding (notacommand to disable the shortcut) to every instance. It will be, either overkill (modify all the styles) or almost impossible (controls instantiated by third party controls).   So, is there a way to disable wpf "class attached" commands in a globally way ? Thank you.

Can connect via SSMS but not SQLCMD/OSQL

I can connect to my SQL 2008 Express Edition server using SSMS.  I cannot connect using OSQL or SQLCMD and my application is having sporadic connection issues.  When I attempt to connect via OSQL, the following error is returned: Error: 18452, Severity: 14, State: 1.  Login failed.  The login is from an untrusted domain and cannot be used with windows authentication. The following are errors present in the SQL errorlog:  Error: 17806, Severity: 20, State: 2.  SSPI handshake failed with error code 0x8009030c while establishing a connection iwth integrated security; the connection has been closed. [CLIENT: <local machine>] Error: 18452, Severity: 14, State: 1.  Login failed.  The login is from an untrusted domain and cannot be used with windows authentication. I see an error in the application event log: Event 6037, LsaSrv  The program sqlservr.exe, with the assigned process ID 1788, could not authenticate locally by using the target name MSSQLSvc/{srvnm}.{workgrp}.net:{SQLinstancenm}.  The target name used is not valid.  A target anme should refer to one of the local computer names, for example, the DNS host name.  Try a different target name. Has anyone else experienced this issue - what else can I look into?      
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend