Running a T-SQL script under different credentials using the SQLCMD.exe utility

I created a batch file and put the following line in it:

runas /user:internal\c39293 "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" -E -S WLDZ9454 -d ChadDb -Q "usp_Test"  

I tried to run the usp_Test stored procedure on the server WLDZ9454 against the ChadDb database.

When I execute it, I just get information about the parameters of the parameters, about the error of the error, so it is not clear to me what I'm doing wrong.

Please note that when I run the code minus the code that tries to run under different credentials, it works:

"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" -E -S WLDZ9454 -d ChadDb -Q "usp_Test" 
+3
source share
1 answer

I suspect because you did not include the program you are using and its parameters in quotation marks.

SqlCmd is executed without any parameters.

 runas /user:internal\c39293 """C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE"" -E -S WLDZ9454 -d ChadDb -Q ""usp_Test"""
+3
source

All Articles