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.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Grant permissions on objects on other DB Servers.
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Ask SQLTeam Question

0 Posts

Posted - 01/09/2006 :  08:28:57  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
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."


United Kingdom
12543 Posts

Posted - 01/09/2006 :  09:05:22  Show Profile  Visit nr's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2019 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000