Please start any new threads on our new site at 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)
 Grant permissions on objects on other DB Servers.

Author  Topic 

Ask SQLTeam Question

0 Posts

Posted - 2006-01-09 : 08:28:57
Dmytro writes "Have a problems with subject. Here is my stor proc.

CREATE PROCEDURE Encrypt.GrantsForEncrypt @GrantRevoke tinyint, @ServerName varchar(50), @DBName varchar(50), @TableName varchar(50), @UserId varchar(50) AS
declare @sqlGrant varchar(200)

set @sqlGrant1 = 'GRANT SELECT, UPDATE ON [' + @ServerName + '].' + @DBName + '.dbo.' + @TableName + ' TO [' + @UserId + ']'

if @GrantRevoke = 0
exec (@sqlGrant)

When I'm trying to run this one as Encrypt user (he has db_securityadmin role in all databases), it says "The object name '' contains more than the maximum number of prefixes. The maximum is 2." where is name of the Database server.
Is there any solutions about this problem??? I need help ASAP.

PS I've tried to use OPENQUERY:
SELECT * FROM OPENQUERY(TEST,'SELECT ''x'' as Testme Use pubs GRANT SELECT ON dbo.authors TO Encrypt')
but it didn't help me. OpenQuery can see only first statement, so Grant statement doesn't take effect.

Thank you."


12543 Posts

Posted - 2006-01-09 : 09:05:22
something like

declare @sqlGrant varchar(200)
set @sqlGrant1 = 'exec [' + @ServerName + '].' + @DBName + '.dbo.sp_executesql N''GRANT SELECT, UPDATE ON ' + @TableName + ' TO [' + @UserId + ']'' '
exec (@sqlGrant1)

Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

- Advertisement -