Questions tagged [sqlcmd]

SQLCMD is a command line tool used to run SQL batches on Microsoft SQL Server.

SQLCMD.EXE is a command line tool used to run SQL batches on Microsoft SQL Server. Get help by running SQLCMD -? and by searching for SQLCMD in the documentation for SQL Server Management Studio. SQLCMD is installed as a part of the Microsoft SQL Server client tools package, and completely supersedes OSQL.EXE.

In addition to command line flags, SQLCMD supports 18 special commands inside SQL files that are not a part of T-SQL syntax. SQLCMD commands aside from "GO" must be prefixed with a colon (:) and appear at the beginning of a line.

SQL Server Management Studio also supports these 18 commands if you select "SQLCMD Mode" from the "Query" menu. This disables IntelliSense.

Reference

SqlCmd on Microsoft TechNet

1169 questions
0
votes
1 answer

slqcmd query to restore database from disk do not work in ant exec task

I am trying whole evening in this sunday to make this one:
HX_unbanned
  • 583
  • 1
  • 15
  • 51
0
votes
1 answer

Difficulty using CAST/CONVERT with SQLCMD in order to assign stored procedure variables

I am attempting to make a stored procedure work by triggering the SP through a batch file using SQLCMD, with user-defined variables. I can already confirm my stored procedure works, because I tested it this way using hard-coded variables. For…
0
votes
1 answer

It is possible to clear connection pool using sqlcmd utility in C# console app when run multiple SQL queries?

I have a console application which uses sqlcmd.exe utility. I have a big SQL file which modify tables structure and some sql which create stored procedures. First I want to apply table modifications and after that the procedures. I wrote something…
Snake Eyes
  • 16,287
  • 34
  • 113
  • 221
0
votes
1 answer

Execute sql script using sqlcmd.exe

C:\>sqlcmd -S(local) -U(sa) -P(password) -i F:\sql.sql HResult 0x3, Level 16, State 1 Named Pipes Provider: Could not open a connection to SQL Server [3]. Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : A network-related or in…
S. S. Rawat
  • 5,943
  • 4
  • 43
  • 59
0
votes
0 answers

Attaching SQL Server 2008 R2 Express database via C#

I am having trouble attaching a SQL Server 2008 R2 Express database. I have to do it via a .Net exe. Here is my code string fileName = @"C:\express\createdb.sql"; ProcessStartInfo psiSqlCmd = new ProcessStartInfo("sqlcmd.exe", @" -S …
0
votes
2 answers

Batch file SQLCMD Restore Loop - Files Disappear

So I've searched and found a lot of info in similar areas, but nothing that quite hits the issue I'm having. I'm working in a test environment and need to restore from the same SQL database backup (.bak) to many named instances of SQL server. All…
0
votes
1 answer

Script error: SQLCMD: Incorrect syntax near the keyword 'with'

When it came to getting tasked with ensuring the backups are in place, I was a little worried because we are using SQL Express and found out that there really isn't a way to manage that without a bit of scripting involved. I am ok with scripting in…
Randall.Cummins
  • 426
  • 1
  • 8
  • 20
0
votes
1 answer

Make sqlcmd work with batch separators

Background information: I am trying to set up a batch job for syncing stored procedures between different sql servers. I did export all stored procedures into seperate .sql files into my folder. Whenever I want to create a new stored procedure or…
Pascal Weber
  • 557
  • 3
  • 11
  • 19
0
votes
1 answer

Using sqlcmd to capture the data from a remote server and putting the excel file in some other server

I have used sqlcmd to capture the required data from a remote server ,which is coming fine . I have used the below query in a batch file - >>"Output_hvac.xls" echo %date% %time% >>"Output_hvac.xls" SQLCMD ... Now This batch file is kept on a local…
user1896796
  • 731
  • 3
  • 9
  • 25
0
votes
2 answers

Streamlining a batch file calling a sql file

We currently have a scheduler to run audits. This scheduler will call a batch file with a parameter, and the batch file calls a sql script (based on the parameter), which in turn calls a stored proc. For each audit that runs, a separate batch file,…
mhopkins321
  • 2,993
  • 15
  • 56
  • 83
0
votes
1 answer

Error testing and control from DOS

I'm running DOS 6.0.6002 on a windows server enterprise system, SP2. SQL Server 2008 R2 (10.50.4000) I have a main control program in DOS. I'm invoking an sql program through sqlcmd. A simplified version looks like this: set sqlsvr=myServer set…
elbillaf
  • 1,952
  • 10
  • 37
  • 73
0
votes
1 answer

Save results to txt file without any other formatting in sqlcmd

When i run this command: sqlcmd -S server -U sa -P xxxxxxx -i d:clients.sql -o D:\clients.txt but in file i have x rows affected, "1> 2> 3> 4> 5> 6> 7> 8>" and many other spaces I wan't only result without any formatting. In sql file i have some…
Fara
  • 217
  • 2
  • 3
  • 9
0
votes
2 answers

Performance: PHP and MS SQL Server: SQLCMD using Exec or Driver

I am currrently making queries to my SQL Server using SQLCMD and I run this from PHPs exec() function. I was hoping to clarify that this isn't as efficient as the driver for SQL Server for PHP:…
Abs
  • 56,052
  • 101
  • 275
  • 409
0
votes
2 answers

Putting Timestamp on the output file using sqlcmd in batch file

I have written the foll sql query in a batch file to fetch the result from a remote server. SQLCMD -S "ServerName -U "uer" -P "Pass" -W -d"Interface" -Q"select LEFT(Zone_Prefix,5)+case when RIGHT(Zone_prefix,1)='N' then '_NORTH_WING' ELSE…
user1896796
  • 731
  • 3
  • 9
  • 25
0
votes
1 answer

SQLCmd Hanging On Complex Batch Scripts

My company is currently using the sqlcmd 2005 for deployment and for some reason on certain SQL scripts it tends to hang even though there are no errors, and if run from management studio it completes successfully. It tends to hang on complex…
Ryu
  • 8,641
  • 10
  • 65
  • 98