Forum Discussion
Login failed for user 'sp'. Reason: Password did not match that for the login provided
- Jul 22, 2024
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
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
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.
- olafhelperJul 22, 2024Bronze Contributor
Invalid object name 'dual'.John_S_Watson , the system object dual exists in Oracle databases, but not in MS SQL Server.
- LainRobertsonJul 22, 2024Silver Contributor
Yeah, it's an easy trap to fall into.
Here's a quick heads up on string delimiters in PowerShell.
Double quotes
Like cmd.exe, double quotes are recognised in PowerShell as a string delimiter, where the dollar sign ($) signifies a substitution of some kind needs to occur. That can be a variable, or even a code block.
For example:
$Movie = "Raiders of the Lost Ark"; # Using double quotes just to illustrate they're fine in PowerShell. Write-Host -Object "$Movie starts at 18:00. Don't forget your popcorn!"; # This time, we're using double quotes.Produces:
Single quotes
Unlike cmd.exe, single quotes are recognised in PowerShell as a string delimiter, where the string is interpreted exactly as it's typed - i.e. there's no parsing for variable and code substitutions, unlike with double quote usage.
For example:
$Movie = "Raiders of the Lost Ark"; # Using double quotes just to illustrate they're fine in PowerShell. Write-Host -Object '$Movie starts at 18:00. Don''t forget your popcorn!'; #This time, we're using single quotes.Produces:
Anyhow, if you see single quotes in any examples you've found, either run those example using PowerShell, or remember to convert the examples to use double quotes instead (and check that single quotes within the string are adjusted accordingly).
This only applies to running something from the command line itself. Once you're inside of sqlcmd, it's business as usual no matter where it was launched from.
Cheers,
Lain