go-sqlcmd icon indicating copy to clipboard operation
go-sqlcmd copied to clipboard

Add a command to create/add a user

Open yorek opened this issue 2 years ago • 4 comments

It would be create if sqlcmd could support the creation of database users/logins. For example, something like

sqlcmd user add -u Davide -p <Password>

for adding a SQL user into the database pointed at by the active context, or

sqlcmd user add -u damauri@microsoft

for adding a AAD user

In both cases the users would be added to the database (creating the login if necessary) and then it would also be stored in the context config so that it could be used when generating the connection string:

sqlcmd config connection-strings -u damauri@microsoft

yorek avatar Mar 16 '23 16:03 yorek

what if sqlcmd dynamically set the initial password or prompted the user to type it? -P parameters on command lines are frowned upon these days. Would we need any hint parameters to distinguish a SQL auth user name from a Windows user name from an AAD user name?

shueybubbles avatar Mar 16 '23 17:03 shueybubbles

That would work too. I would still allow to manually set a password, but I agree to make the default option the autogeneration

yorek avatar Mar 16 '23 17:03 yorek

You can use the command sqlcmd config add-user

I checked and the problem is with the help documentation. PS is using $Env:VariableName instead of SET VariableName

I manage to add an user with this code:

PS C:\Users\felip> $Env:SQLCMDPASSWORD="Passw0rd"
PS C:\Users\felip> sqlcmd config add-user --name felipe --username felipe --password-encryption none
User 'felipe' added
PS C:\Users\felip>

felipeschneider88 avatar May 12 '23 19:05 felipeschneider88

That doesn't create the login/user in the SQL Server database though.

yorek avatar May 13 '23 00:05 yorek