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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Granting Access to a database other than the current one.

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-01-03 : 12:09:05
John writes "Simple question, I want to grant access to a database other than the current one in a stored procedure based on a database name in a variable.


The current syntax
sp_grantdbaccess [@loginame =] 'login'[,[@name_in_db =] 'name_in_db' [OUTPUT>

Does not provide a parameter for specifying another database to add the user to and assumes the current database. Ideally it would be nice if it had a second parameter for the database name I could pass in such as the context for the command. At least this would make a lot of sense in terms of the interface. Alas, no such luck.

The help file suggests:
USE DatabaseName
sp_grantAccess @Login

However this just won't work because the USE statement will not take a variable for the database name.

Next attempt:

EXEC 'USE ' + @Databasename + '; sp_grantAccess UserA'

This would work, except it breaks the ownership chain and causes problems when I was depending on the fact that the SA owned the stored procedure for this to execute.

Help!"

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2003-01-03 : 12:19:38
use database.dbo.sp_grantdbaccess

Go to Top of Page
   

- Advertisement -