Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't add user to db_datareader via script

I have the following script:

ALTER ROLE [db_datareader] ADD MEMBER [DomainGroup123]

when I run this against SQL Server 2008 R2 I get this error:

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'ADD'.

I have looked online, and found examples that use this exact statement (but with a different user.)

I have double checked that the login exists and is a valid user on the database I am using. Also I have SA permissions on the server.

What am I mssing?

like image 421
Vaccano Avatar asked Feb 25 '13 23:02

Vaccano


People also ask

How do I add a user to a database role?

Right-click the role you want to edit and select Properties. In the Database Role Properties -database_role_name dialog box, in the General page, click Add. In the Select Database User or Role dialog box, under Enter the object names to select (examples), enter the login or database role to add to this database role.

How do I grant permission to SQL user?

To grant permissions for the user, switch to the Object Permissions tab. In the Objects block, select the database object on which you want to grant privileges. In the Available Privileges block, select the permissions to be assigned and click Save.


1 Answers

Use sp_addrolemember.

EXECUTE sp_addrolemember db_datareader, 'UserName'
like image 183
supergrady Avatar answered Sep 27 '22 22:09

supergrady