0

I have an AD login added to a SQL Server group. The SQL Server group has the sysadmin role.

When the user logs in they connect correctly

account name    type    privilege   mapped login name   permission path
domain\test     user    admin       domain\test         domain\groupwithsysadmin

When they execute a stored procedure in a user database, it errors out for not having execute permissions.

The EXECUTE permission was denied on the object 'SomeFunction', database 'SomeDatabase', schema 'Test'.

If I execute as user in the database, the same things happens.

use SomeDatabase 
GO 
EXECUTE AS USER = 'domain\test';  
select Test.SomeFunction ('ComponentTest')
REVERT; 
GO

The EXECUTE permission was denied on the object 'SomeFunction', database 'SomeDatabase', schema 'Test'.

If I execute as the login it works.

EXECUTE AS login= 'domain\test'; 
select SomeDatabase.Test.SomeFunction ('ComponentTest')
REVERT; 
GO

I am stumped as to why a the login will not carry the sysadmin privileges when using the database.

8
  • Is your domain\test User orphaned from the Login?
    – J.D.
    Commented Oct 25 at 19:03
  • It is an AD login as part of a group, so was never a login/user on the server/database.
    – Pooeye136
    Commented Oct 26 at 20:03
  • Regardless, whichever Login and User that represents the AD Group. Are they orphaned?
    – J.D.
    Commented Oct 26 at 23:36
  • Indeed sounds like the AD group itself is orphaned. Try SELECT dp.name, dp.type, dp.sid, sp.sid AS server_sid, sp.type AS server_type FROM sys.database_principals AS dp LEFT JOIN sys.server_principals AS sp ON dp.sid = sp.sid WHERE dp.principal_id = DATABASE_PRINCIPAL_ID(); dbfiddle.uk/x8WN9yY0 and show us the results, the last two columns will be null if orphaned. Commented Oct 27 at 0:57
  • Am seeing no evidence of the user or group in question being orphaned in the database.
    – Pooeye136
    Commented Oct 28 at 9:06

1 Answer 1

0

It's possible you have encountered a limitation of the EXECUTE AS statement. Here's an excerpt of the doc that might be related to your problem:

While the context switch to the database user is active, any attempt to access resources outside of the database will cause the statement to fail. This includes USE database statements, distributed queries, and queries that reference another database that uses three- or four-part identifiers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.