Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Permission issue on running dynamic SQL

$
0
0
Hi Everyone.We have a stored procedure called SP1. This SP is being called by user1. Since User1 does not have direct access to table1 in database1, so we have to execute the SP by 'with execute' option using a user2 who has read access to table1Below is the definition of SP1 .Use database1goalter procedure SP1@TableName as varchar( 50)with execute as User2asdeclare @SqlStr varchar (200 )select @SqlStr = " select * from database1.dbo.table1 t1 inner join " + @TableName + " t2 on t1.code = t2.code"exec sp_executesql @SqlStrgowhen I ran exec SP1 'tempdb.User1.table2' , I faced with below error message.The SELECT permission was denied on the object 'table2', database 'tempdb', schema 'User1'.User2 has read access to Table1 in database1 and also I have given select permission on User1 schema on tempdb. But still it is complaining about select permission on table2.I would appreciate if someone helps me on this issue.Thanks

Viewing all articles
Browse latest Browse all 3145

Trending Articles