Forum Discussion

John_S_Watson's avatar
John_S_Watson
Copper Contributor
Jul 21, 2024
Solved

Login failed for user 'sp'. Reason: Password did not match that for the login provided

Please excuse my ignorance of basic SQL Server admin. Any advice much appreciated. I cannot login using passwords. For example:

C:\Users\john>
C:\Users\john>sqlcmd -s jw-lat -e
1> create login sp with password='sp';
2> go
create login sp with password='sp';

1> create user sp for login sp;
2> go
create user sp for login sp;

1>  alter server role sysadmin add member [sp];
2> go
 alter server role sysadmin add member [sp];

1> exit

C:\Users\john>
C:\Users\john>sqlcmd -s jw-lat,1433 -U sp -P 'sp'
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed for user 'sp'..

C:\Users\john>

In the SQL Server log I see this,

Date		Sun 21 07 2024 14:26:33
Log		SQL Server (Current - Sun 21 07 2024 14:26:00)

Source		Logon

Message
Login failed for user 'sp'. Reason: Password did not match that for the login provided. [CLIENT: <local machine>]

I have tried any number of variations on case and quotes. I must be missing something really basic?

Thankyou for any insight.

 

  • John_S_Watson 

     

    I'm taking a wild guess that you're running the commands from the Command Prompt (the old-school environment that came well before PowerShell).

     

    If that's true, then it's important to know that the command prompt processor only recognises double quotes as string delimiters, meaning the password you're attempting to log in with is actually the value:

     

    'sp'

     

    Which doesn't match the earlier password you set inside the sqlcmd session of:

     

    sp

     

    So, in other words, for your second sqlcmd where you're trying to log in using the new sp account, use the following for the password:

     

    • sp
    • "sp" (Again, the command prompt recognises double quotes as string delimiters.)

     

    Do not use 'sp' (as the command prompt will include single quotes in the actual password value).

     

    Cheers,

    Lain

5 Replies

  • LainRobertson's avatar
    LainRobertson
    Silver Contributor

    John_S_Watson 

     

    I'm taking a wild guess that you're running the commands from the Command Prompt (the old-school environment that came well before PowerShell).

     

    If that's true, then it's important to know that the command prompt processor only recognises double quotes as string delimiters, meaning the password you're attempting to log in with is actually the value:

     

    'sp'

     

    Which doesn't match the earlier password you set inside the sqlcmd session of:

     

    sp

     

    So, in other words, for your second sqlcmd where you're trying to log in using the new sp account, use the following for the password:

     

    • sp
    • "sp" (Again, the command prompt recognises double quotes as string delimiters.)

     

    Do not use 'sp' (as the command prompt will include single quotes in the actual password value).

     

    Cheers,

    Lain

    • John_S_Watson's avatar
      John_S_Watson
      Copper Contributor
      Thankyou. As you thought, I am running a cmd.exe shell. I had no idea that all the examples I've been seeing were in a power shell (which I've never used, anyway). So I can get in following your explanation:
      C:\Users\john>
      C:\Users\john>sqlcmd -s jw-lat,1433 -U sp -P sp
      1> select current_user from dual;
      2> go
      Msg 208, Level 16, State 1, Server jw-lat, Line 1
      Invalid object name 'dual'.
      1> select current_user;
      2> go


      --------------------------------------------------------------------------------------------------------------------------------
      dbo


      (1 rows affected)
      1>

      Thankyou again.
      • olafhelper's avatar
        olafhelper
        Bronze Contributor

         


        Invalid object name 'dual'.

        John_S_Watson , the system object dual exists in Oracle databases, but not in MS SQL Server.

Resources