I'm using Sql Server 2008 and have a proc that uses sp_executesql inside. I keep getting the following error when executing the proc through ASP.NET:
The SELECT permission was denied on the object 'MyTable', database 'MyDatabase', schema 'dbo'.
I've done lots of research on this and most people point to the fact that I need to grant select permission on the underlying table that my dynamic query reads from. Well, I've done this and it still doesn't seem to work:
select object_name(major_id) as object,
user_name(grantee_principal_id) as grantee,
user_name(grantor_principal_id) as grantor,
permission_name,
state_desc
from sys.database_permissions
where major_id = object_id('User') and
class = 1
Results: MyTable public dbo SELECT GRANT MyTable guest dbo SELECT GRANT MyTable myuser dbo SELECT GRANT MyTable NT AUTHORITY\NETWORK SERVICE dbo SELECT GRANT
As you can see, I've gone overkill on trying to grant select on the underlying table. I've even re-written my proc down so that it only references MyTable in the dynamic sql. I've even granted all of the above users "execute" permission on the proc... No luck.
The "myuser" above is the username in my connectionstring in the web.config.
Am I missing something here?
Thanks! Dave
WITH EXECUTE AS
defined? – Crossjack