sqlcmd Login failed for user sa

Sachin Kainth picture Sachin Kainth · Jun 7, 2012 · Viewed 10.7k times · Source

I am trying to run this command

sqlcmd -U "sa" -P "mypassword" -S (local)\SQLEXPRESS -Q "ALTER DATABASE mydatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE"

from a .bat file but it is failing with the error

"Login failed for user 'sa'

I have gone to the Login tab under the Security tab in SSMS and changed the password of the sa account to the password in the .bat file, but still get this error.

I have tried to log into SSMS with the sa account using these credentials and with SQL Server authentication but I get the same error. I have stopped and started the SQL Server service, nothing works.

Any idea what I must do?

Answer