sql-serversql-server-2008command-line-argumentssqlcmdosql

SQLCmd Password parameter with comma


We have a SQL server for which the password contains comma (','). Since we use the same in SQLCmd, the process fails. Please find the query which we are using below

SQLCmd -U%1 -P%2 /S%servername% /dDbName -Q"EXEC sp_test null, 'DbName', '\ProcessLog\', 'STORE'" >> %NB4%\ProcessLog.log

The string is passing from a different command file.

But the password contains comma (','), so that the process is not able to connect to SQL Server

Is there a way to add escape character in the parameters? Tried using double quotes ('"'), but no luck. Any help will be much appreciated.


Solution

  • I have found a solution for this. Since comma was there in the password, the part after the comma was considering as the third parameter and since the first parameter were not matching with the actual password, the connection were not getting established. Here is the solution for this. Worked perfectly for me.

    IF "%3" NEQ "" GOTO ThreeParm
    IF "%3" == "" GOTO TwoParm
    :ThreeParm
    SQLCMD -U%1 -P%2,%3 /S%servername% /dTestDB -Q"EXEC sp_test null, 'TestDB', '\Folder\', 'STORE'" >> %NB4%\Folder.log
    :TwoParm
    SQLCMD -U%1 -P%2 /S%servername% /dTestDB -Q"EXEC sp_test null, 'TestDB', '\Folder\', 'STORE'" >> %NB4%\Folder.log