views:

23

answers:

2

My requirement is that user performing alter CANNOT be sysadmin (it can have all other rights but not sysadmin).

I am running a query from local server which should modify a remote one

EXEC ('ALTER DATABASE REMOTEDB MODIFY FILEGROUP ftfg_REMOTEDB NAME=ftfg_REMOTEDB') at [REMOTESERVER]

This query works once I add sysadmin right to the user but without the right, it give the following error:

The server principal "USERWITHOUTSYSADMIN" is not able to access the database "REMOTEDB" under the current security context.

I am on SQL Serve 2008.

Please Help!

A: 

Put the EXEC command in a stored procedure and grant execute on the procedure to the user. It won't STOP a sysadmin from executing it, but it will allow others to execute it as well. Be VERY, VERY careful with this!

md5sum
can I add execute to the user to the existing sp_executesql procedure and use that procedure?
Chicago
FYI, This did now not work but it was a very good idea
Chicago
Sorry, I know we did something like this at a place I used to work, but that's been a long, long time ago, and it was a pretty messy thing... Is it possible to give a broader explanation of what it is you're trying to accomplish? There may be a better overall solution before you implement something like this.
md5sum
A: 

Can you allow the user to impersonate someone with the appropriate permissions?

EXEC ('ALTER DATABASE REMOTEDB MODIFY FILEGROUP ftfg_REMOTEDB NAME=ftfg_REMOTEDB') 
    AS USER = 'UserWithAppropriatePermissions'
    AT [REMOTESERVER]
Joe Stefanelli
That's the problem. Is seems that the only appropriate permission is to give the user sysadmin rights (which I cannot do). So, I cannot give sysadmin rights to the user on local server or remote. I tried to do this with sa but local user does not have enought permissions to impersonate as sa:)
Chicago
Can you grant the user ALTER permissions on the Database Object? That should be sufficient for your purposes.
Joe Stefanelli
How do I do that? I tried doing that via UI but that did not seem like a reliable way (right click on db - > permissions -> alter). Can I do with sql?
Chicago
Via SSMS, drill down through the folders: Databases -> YourDatabase -> Security -> Users. Double click on the user you want to modify. Click "Securables" in the left hand pane. Click "Search..." in the main pane. Choose radio button "All objects of the type..." and click OK. In the pop-up window, Check Object Type "Databases" and click OK. Scroll through permissions in lower panel and check box for "Grant" next to the "Alter" permission.
Joe Stefanelli
Just tried that and that did not work :(
Chicago
One more thing I realized is that it is not only for alter but for select as well. I think I am missing some general access permission?
Chicago