Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Error while executing Tsql from sqlcmd

Author  Topic 

Sanders_2503
Starting Member

1 Post

Posted - 2011-10-08 : 16:51:36
Dear Experts,

I am trying to execute a stored procedure through sqlcmd connecting to a remote database from a batch script. While I am able to connect to the remote server, its throwing error to execute the Tsql script.
Here is the batch script I am executing -


:MAIN


'C:\Program Files\Microsoft SQL Server\100\Tools\Binn\sqlcmd.exe' -Spportal52.db.111111.hosted.com -Uportal123 -Pxxxxxxx -dportal123 -Q"EXEC C:\Documents and Settings\sr\Desktop\ftp test\sps_filercvdts_import.sql 'C:\list_of_file_tsrcvd.txt'"


This is the error I am getting -



C:\Documents and Settings\sr\Desktop\ftp test>"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\sqlcmd.exe" -Spportal52.db.111111.hosted.com -Uportal123 -Pxxxxxxx -dportal123 -Q"EXEC C:\Documents and Settings\sr\Desktop\ftp test sps_filercvdts_import.sql 'C:\list_of_file_tsrcvd.txt'"
Msg 102, Level 15, State 1, Server P3NWDSHSQL009, Line 1
Incorrect syntax near 'C:'.



The password field above is masked.

I guess it's because my sql file is on my local drive C:\ whereas my sqlcmd connects to the remote db and expects to see the sql file over there.

Request the experts to throw some light on this as to how do I execute my local sql file when I connect to the remote db through sqlcmd.
Also note that I am passing a text file as an input to the sql file which will load the text file to the table.

Thanks in advance and appreciate your response.




Thanks,
Sanders

paultech
Yak Posting Veteran

79 Posts

Posted - 2011-10-09 : 06:47:57
see the following link

http://stackoverflow.com/questions/5936557/running-a-t-sql-script-under-different-credentials-using-sqlcmd-exe-utility

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-09 : 12:32:09
try providing unc path in form \\yourmachinename\....

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -