Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Aytan
Starting Member
1 Post |
Posted - 2002-08-30 : 16:58:42
|
| Hi:I am working on application which requires to assign administrator access to sql databases to specific users.I wrote code and tested it in Query Analyzer and it worked properly. When I used this code in stored procedure it didn't work. So, here what exactly I need:1. Create login;2. Add this user to all databases on Server;3. Give Systems Admininistrator server role;4. and assigned to db_owner role;I do it by the following:EXEC sp_addlogin 'TestUser', 'TestPassword'And I repeat the following code for each database which I want this user to be addedIn this example I will use only two databases MYDB and master db---------------------------------------------------------Use MyDBEXEC sp_defaultdb @userName, 'MyDB'EXEC sp_grantdbaccess @userNameEXEC sp_addrolemember db_owner, @userNameEXEC sp_addsrvrolemember @userName, 'sysadmin'-------------------------------------------------------------------Use masterEXEC sp_defaultdb @userName, 'master'EXEC sp_grantdbaccess @userNameEXEC sp_addrolemember db_owner, @userNameEXEC sp_addsrvrolemember @userName, 'sysadmin'-----------------------------------------------------------------When I use this code in stored procedure I get eror about 'USE' statement, which cannot be used in stored procedure.So, does anyone can help me find what I can use to get the same result?Or probably tehre is different way to achieve the same result?Thank you in advance for help. |
|
|
jasper_smith
SQL Server MVP & SQLTeam MVY
846 Posts |
Posted - 2002-08-30 : 17:34:49
|
| All you need to do is add the login to the Sytem Administrator fixed server database role , the rest is irrelavent. However, I would seriously question why they need sysadmin access, just add them to the db_owner fixed database role and they will be able to danything in the database.HTHJasper SmithEdited by - jasper_smith on 08/31/2002 16:34:02 |
 |
|
|
|
|
|
|
|