Sql-server – Way to run SQLCMD without storing password in text format

database-recommendationsql server

Is there a way to run sqlcmd from a batch file where I don't want to store the password in plain text format. I have done some research and found the system variables method(store password in system variables) but the requirement is not to store a password in text format anywhere in the system.

The user that is logging into the system should not be able to see the password for sql server and still run the batch file containing sqlcmd and restore command

Any help, pointers are appreciated.

Best Answer

If you are using SQL Logins, then basically, no. You'll want to have sqlcmd use the person's domain login to connect to the SQL Instance (the -E parameter instead of -U and -P). You can use a login trigger to ensure that they are only able to connect via sqlcmd if you want to prevent them from logging in via SQL Server management studio (it isn't a perfect fix, but it'll stop 99% of people).