SQL Server 2008 R2 – Automatically Granting Permissions to Application Created Databases

sql serverwindows

So I have an application that automatically creates a new database after the database it is currently in reaches a fixed number of rows. I need to be able to automatically assign a user within the installation the db_datareader role for the automatically created database. I'm kind of at a loss here, any help is greatly appreciated.

Best Answer

Add the user to the DB_READER role. Like this:

use YourNewDb
go

exec sp_addrolemember db_datareader, UserName (or) [domain\netusername] (or) suser_sname()
go

Copied from https://stackoverflow.com/questions/456346/t-sql-to-grant-db-datareader-and-db-datawriter