Follow sqlserver-dba.com

Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions

SQLServer-DBA.com Links

Dba_db2_button

dba-ninja.com

SQL Server DBA Jobs

How to use a blank password with SQLCMD

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"


 Read More on SQLCMD

Powershell : SQLCMD and invoke-expression

SQL Server DBA Tools

SQL Server – Open SSMS without the splash screen graphic

 


Author: Tom Collins (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

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.

Working...

Post a comment on How to use a blank password with SQLCMD


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer