24 February,2016 by Tom Collins
Question : I'm trying to execute a stored procedure SQLCMD which requires the use SQL Authentication Login Method.
I know that there shouldn't be a blank password, but in this test case we are attempting to run the SQLCMD program with a SQL Login but no password.
Don't ask why , it's some legacy code workaround concocted by the application team.
sqlcmd -S SERVER1\myinstance -d mydb -U user1 -P -s, -Q "EXEC dbo.mysp value1,value2"
This returns with the following Error message
Sqlcmd: '-P': Missing argument. Enter '-?' for help.
I've tried running without the -P switch and this gives me a password prompt. I've also tried setting the SQLCMDPASSWORD session environment variable and I still getting the Missing argument response.
Is there a way around this problem or are blank passwords not supported through SQLCMD using the SQL Authentication mode?
Answer: Blank passwords are supported using SQLCMD and SQL Authentication. This all comes with the
standard warning about enforcing password policies etc and security policies.
The way to utilise a blanl password is to use double quotes ("").
In the example you've presented use :
sqlcmd -S SERVER1\myinstance -d mydb -U user1 -P "" -s, -Q "EXEC dbo.mysp value1,value2"
Powershell : SQLCMD and invoke-expression
SQL Server – Open SSMS without the splash screen graphic
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |