Dynamic sql within stored procedure security context
Hello,
We have stored procedure in database dbA, that runs (among other things) dynamic sql. It accesses several dbs, not just the one where stored procedure is (dbA). Db user domainnameusername has EXECUTE permission on this stored procedure.
When user runs this stored procedure, it is failing with the error that says “the server principle “domainnameusername” is not able to access the database “dbB” under the current security context“
Note that domainnameusername clearly exists in database dbB, it is not disabled, and following sql proves it:
select * from dbB.sys.sysusers where name = ‘domainnameusername’
I know that dynamic sql within stored procedure changes security context of its execution, but I would expect that since this user exists in all dbs (including dbB) it should not be the problem.
Does anybody have any idea what could be the issue?
Thanks
Hello, We have stored procedure in database dbA, that runs (among other things) dynamic sql. It accesses several dbs, not just the one where stored procedure is (dbA). Db user domainnameusername has EXECUTE permission on this stored procedure. When user runs this stored procedure, it is failing with the error that says “the server principle “domainnameusername” is not able to access the database “dbB” under the current security context” Note that domainnameusername clearly exists in database dbB, it is not disabled, and following sql proves it: select * from dbB.sys.sysusers where name = ‘domainnameusername’ I know that dynamic sql within stored procedure changes security context of its execution, but I would expect that since this user exists in all dbs (including dbB) it should not be the problem. Does anybody have any idea what could be the issue? Thanks Read More