Sqlcmd Error "The filename, directory name, or volume label syntax is incorrect"

Viewed 2983

I create a bat file for the first time, and have the following issue: my command is running just fine when I type it directly into the command prompt, but it's not running through the bat file I created. The script is:

@echo off
sqlcmd -S DESKTOP-55JKCD5\SQLEXPRESS -i “C:\Users\Didi\Documents\SQL\test.sql” -o “C:\Users\Didi\Documents\SQL\output.csv” -s”,”

I get the following message from cmd:

Sqlcmd: Error: Error occurred while opening or operating on file ôC:\Users\Didi\Documents\SQL\test.sqlö (Reason: The filename, directory name, or volume label syntax is incorrect).

I can't understand what's wrong, provided that I don't have any issues when typing directly in cmd.

I'm begging for your advice, guys! Bat files are totally new for me, apologies is asking a stupid question.

2 Answers

If you are running this exe from Azure Dev Ops you can also get this issue if there is a new line in the definition of the step in the Release or Pipeline. The step is multiline so it is difficult to spot. It's the difference between:

ServerRoleMembership;ServerRoles;RoleMembership;Permissions" /v:Environment=$(Environment) /Diagnostics:true
 /p:ScriptDatabaseOptions=false

and

 ServerRoleMembership;ServerRoles;RoleMembership;Permissions" /v:Environment=$(Environment) /Diagnostics:true /p:ScriptDatabaseOptions=false 

Both look same in Dev Ops, it's only when you copy them out to notepad you will see the new line

Related