3

I have an SQL Azure database, and I'm able to connect to it using SQL Server Management Studio. When connecting to it, it displays

myServer.database.windows.net (SQL Server 12.0.2000.8 - myUser)

However, when I'm using the SQLCMD utility on the same machine, against the same SQL Azure server, with the same credentials, it always answers

Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : Login failed for user 'myUser'

The syntax I'm using is

sqlcmd -S tcp:myServer.database.windows.net -U myUser@myServer -P "myPassword"

I tried everything I could think of:

  • Added the port: myServer.database.windows.net,1433
  • Removed the tcp: protocol
  • Enclosed the user in double quotes, like the password
  • Tried the -I and -C command line options
  • Combinations of the above.

The error is always the same.

Is there some specific flag that has to be activated for SQLCMD to work with SQL Azure? Any other ideas?

2 Answers 2

2

The error was some encoding issue with Powershell. I suppose the password's special characters were not read correctly by Powershell.

In cmd.exe, it worked flawlessly.

1
  • 1
    I'm glad you sorted your issue. If we just take a look at your question... it makes no mention of powershell in the tags or in the content. Perhaps you could also add the powershell code to your question and tag it powershell
    – Nick.Mc
    Commented May 11, 2017 at 0:22
0

add -G parameter in your command:

sqlcmd -S tcp:myServer.database.windows.net -U myUser@myServer -P "myPassword" -G
2
  • 4
    This would be much better if you explained what this did and why it would fix the problem. Commented Jul 19, 2019 at 8:22
  • Per Microsoft Docs on sqlcmd > -G (use Azure Active Directory for authentication) But I don't think this would have actually fixed the issue. Per the OP he is using the option > -U myUser@myServer That tells me he is using a local SQL Server UserId not Azure Active Directory. I found this article while trying to solve the same situation, just a different error. But I was not able to get it work, I am attempting to use Azure Active Directory.
    – Semperfi89
    Commented Feb 9, 2022 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.