Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 Stored Procedure Trigger Permission Problem

Author  Topic 

phenreid
Starting Member

29 Posts

Posted - 2011-11-08 : 00:07:03
SS8/R2

I have a sproc executed by asp.net (4.0). The user has been given execute permission on it.

sproc updates table "A".

Table "A" has a trigger associated with it. It's an audit trail trigger that uses dynamic SQL.

I'm using SQL Server Authentication in ASP. The user has a "public role" overall. In the specific database, it has the sprocs in the securables all with execute permission.

When executing the sproc from asp, I get an error that the trigger is not found or does not have adequate permission. Only granting the "control" permission on the underlying Table "A" solves this problem, but I do not really wish to give the user "control" permission. It sort of defeats the purpose of exposing the sprocs for execute-only. I've tried every combo of permission, but none of them work accept control on the table with the trigger.

What's the best solution?

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-08 : 00:34:45
That's one of the unfortunate side effects of using dynamic SQL as it doesn't execute in the same context as the stored procedure, so the stored procedure permission is not enough.

Consider rewriting the trigger so that it doesn't use dynamic SQL.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2011-11-08 : 01:58:24
One way would be to impersonate the user against an user who has rights to the table and then execute the trigger using that users context.Put something like this in the trigger

Create trigger abc
for insert as
execute as user='the user who has rights to table'
'Your Dynamic sql'
Exec(Dynamicsql)
revert


What will happen here would be that the user wont have explicit access to the table but the trigger will get executed using a different user context who has rights for the table.


PBUH

Go to Top of Page
   

- Advertisement -