Add SQL user to a role via TSQL

Came across with a situation where a database was in standby mode (secondary server) and the SQL user with which I was trying to access had no access on the database.

The database was not allowing to change anything with regards to configuration from Management Studio so eventually had to add the user in sysadmin from the following TSQL:

— myUser being added to role sysadmin

–SELECT * FROM master..syslogins

EXEC master..sp_addsrvrolemember @loginame = N’myUser’, @rolename = N’sysadmin’



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s