TheBugSlayer
Programmer
All,
I have a trigger that writes some data into an audit table. Among that data is the client's IP address, which it retrieves from the sys.dm_exec_connections DMV. When the user does not have permission to select from the DMV a The user does not have permission to perform this action. error is returned, obviously. These are service accounts that I must grant VIEW SERVER STATE permission to.
However, I would like to instead the trigger instead under the security profile with the proper permission, VIEW SERVER STATE. I have created the trigger with a
clause alright. Nonetheless, when I run an update statement on the table to test the trigger, it still fails with the same error! I have tried different impersonations to no avail.
What am I doing wrong? Is there any way I can switch the security context just for the call to the DMV and switch it back to the current user before the next statement? EXECUTE AS CALLER may not work for all logins, obviously.
PS: I am writing the code in SQL Server 2012 MS but the underlying DB is in 2008 R2.
Thanks for your help.
MCP SQL Server 2000, MCTS SQL Server 2005, MCTS SQL Server 2008 (DBD, DBA)
I have a trigger that writes some data into an audit table. Among that data is the client's IP address, which it retrieves from the sys.dm_exec_connections DMV. When the user does not have permission to select from the DMV a The user does not have permission to perform this action. error is returned, obviously. These are service accounts that I must grant VIEW SERVER STATE permission to.
However, I would like to instead the trigger instead under the security profile with the proper permission, VIEW SERVER STATE. I have created the trigger with a
Code:
WITH EXECUTE AS 'Domain\administrator'
What am I doing wrong? Is there any way I can switch the security context just for the call to the DMV and switch it back to the current user before the next statement? EXECUTE AS CALLER may not work for all logins, obviously.
PS: I am writing the code in SQL Server 2012 MS but the underlying DB is in 2008 R2.
Thanks for your help.
MCP SQL Server 2000, MCTS SQL Server 2005, MCTS SQL Server 2008 (DBD, DBA)