SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


grant access to all databases


grant access to all databases

Author
Message
Zeal-DBA
Zeal-DBA
Old Hand
Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)

Group: General Forum Members
Points: 337 Visits: 1125
hello experts,
i have around 600 databases in my server, a user need select access of all the databases. will i have to go one by one in all the dbs and create tht user and give datareader role to him. or is thr any shorter way to do so????

thanks in advance
Adiga
Adiga
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2660 Visits: 21012
Cross post. All responses at http://www.sqlservercentral.com/Forums/Topic1022684-391-1.aspx

Pradeep Adiga
Blog: sqldbadiaries.com
Twitter: @pradeepadiga
Ramdas Baghel
Ramdas Baghel
SSC-Addicted
SSC-Addicted (400 reputation)SSC-Addicted (400 reputation)SSC-Addicted (400 reputation)SSC-Addicted (400 reputation)SSC-Addicted (400 reputation)SSC-Addicted (400 reputation)SSC-Addicted (400 reputation)SSC-Addicted (400 reputation)

Group: General Forum Members
Points: 400 Visits: 964
Hi,

You have to apply below mention script with your all database..

Syntax
USE [DatabaseName]
GO
CREATE USER [UserName] FOR LOGIN [LoginName] WITH DEFAULT_SCHEMA =schema_name
GO
EXEC sp_addrolemember 'db_datareader', 'UserName'

Script For All Databases
---------------------------------------------------------------------
USE master
GO
DECLARE @LoginName varchar(256)
SET @LoginName ='YourLoginName'

SELECT 'USE [' + Name + ']'
+ ';'
+ 'CREATE USER [' + @LoginName + '] FOR LOGIN [' + @LoginName + '] WITH DEFAULT_SCHEMA =dbo'
+ ';'
+ 'EXEC sp_addrolemember ''db_datareader'', '''+ @LoginName + ''''
AS ScriptToExecute

FROM sys.databases
WHERE name NOT IN ('Master','tempdb','model','msdb') -- Avoid System Databases
AND (state_desc ='ONLINE') -- Avoid Offline Databases
AND (source_database_id Is Null) -- Avoid Database Snapshot
ORDER BY Name
---------------------------------------------------------------------

Copy output of this select query and open new query window and then execute..

Ram
MSSQL DBA
ngazit
ngazit
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 85
Thank you, it was helpfull.

Nira



SQLBuzz
SQLBuzz
SSC Rookie
SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)

Group: General Forum Members
Points: 33 Visits: 320
Edit posted
kapil_kk
kapil_kk
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3067 Visits: 2766
You arw getting this error because you have specified db_datareader, db_datawriter' as a single role and due to this sql server not able to identify it as a valid role..... Specify both roles seperatly and it will work

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
SQLAssAS
SQLAssAS
Say Hey Kid
Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)

Group: General Forum Members
Points: 696 Visits: 1220
600 databases on one instance?? That maintenance schedule must be fun!
SQLBuzz
SQLBuzz
SSC Rookie
SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)

Group: General Forum Members
Points: 33 Visits: 320
Typo my bad, it is 60 Databases...but we do have 200+ on 4 node cluster environment
pmaceke
pmaceke
SSC Journeyman
SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)

Group: General Forum Members
Points: 75 Visits: 100
I'm trying to use your post to grant a group-user read access to all databases, but I get the error message below.
Please assist

Msg 15259, Level 16, State 1, Line 1
The DEFAULT_SCHEMA clause cannot be used with a Windows group or with principals mapped to certificates or asymmetric keys.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search