I'm scheduling a task in Windows to connect to an off-site SQL Server every night to run a query and save the results as a .CSV file. I'm able to connect to the SQL Server using SSMS with no problems at all. I'm able to connect to the SQL Server manually using SQLCMD from a command prompt with no problems at all. My issue is I cannot use SQLCMD within a batch file. The syntax I'm using is......
sqlcmd -S ServerName\InstanceName -d DatabaseName -U UserName -P Password
If I manually enter that into my command window, it works like a champ.
If I try to connect using a batch file, I get the error, "Msg 18456, State 1, Server ServerName\InstanceName, Line 1 Login failed for user 'UserName'.
I've also tried right clicking the batch file and running as administrator with no success. Thank you in advance for your help.
Travis
UPDATE
I just now discovered that if you take the -P Password parameter out of the batch file, you will be prompted for the password. After entering my password, I'm logged in successfully. Are there limitations on passing passwords to the SQL server from a batch file? Being that this is an off-site server that's not on our network, I'm unable to use Windows Authentication.