Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlcmd doesn't run from .bat file, but it does work from a command line

I am trying to run a simple batch file that calls a backup script I have in SQL Server. When I enter this into a command line, it works but when run from a .bat file, nothing happens. No errors, no output at all.

sqlcmd.exe -S WIN-FPQSHCEB0EM -E -Q "EXEC sp_BackupDatabases @backupLocation='E:\Backups\', @databaseName=’xxxxxx’, @backupType='F'"
PAUSE
  • I've tried it with and without the server name (-S)
  • I've explicitly set a path, to no affect.
  • When executing sqlcmd, I've used the entire path.

Any idea why this wouldn't work?

like image 376
JonnyBravoJr Avatar asked May 20 '26 13:05

JonnyBravoJr


1 Answers

I know this is an old question, but it happened to me recently!

Its because of the quote marks in your SQL... I couldn't find a method to escape them, so I resorted to using a script file.. Put your SQL into the script file, then use the "-i " to run that, instead of inline SQL...

like image 184
James Joyce Avatar answered May 22 '26 05:05

James Joyce