all groups > sql server programming > june 2007 >
You're in the

sql server programming

group:

Granting user exec on stored proc with dynamic sql without granting select priv on sql query table


Granting user exec on stored proc with dynamic sql without granting select priv on sql query table donet programmer
6/8/2007 6:59:06 PM
sql server programming:
I am writing a stored procedure which executes a dynamic sql statement
on a certain table.
Something similar to below

Create Procedure dbo.myproc
As

-- create dynamic sql query
Declare @query varchar(4000)

set @query = 'Select * from TableA'

--
--
--

exec(@query)

GO

I want to grant user exec rights on this stored procedure. But when I
try executing query, I get error saying access to TableA is denied. I
gave user Select access on the table, after which I was able to
execute the stored procedure.

Is there a way I can avoid granting the user Select access to the
table, still allowing him to execute the stored proc.
Re: Granting user exec on stored proc with dynamic sql without granting select priv on sql query table amish
6/9/2007 3:14:03 AM
[quoted text, click to view]

Owner of procedure and table shoud be same.
then you need to only give exec permission on procedure.

Regards
Amish Shah
http://shahamishm.tripod.com
Re: Granting user exec on stored proc with dynamic sql without granting select priv on sql query table Dan Guzman
6/9/2007 6:47:57 AM
[quoted text, click to view]

In SQL Server 2000, you must grant execute permissions to the underlying
objects because dynamic SQL breaks the ownership chain. In SQL 2005, you
can either sign the proc with a certificate or specify EXECUTE AS so than an
alternate security context is used when the ownership chain is broken.

See http://www.sommarskog.se/dynamic_sql.html for a more complete
discussion.


--
Hope this helps.

Dan Guzman
SQL Server MVP

[quoted text, click to view]
Re: Granting user exec on stored proc with dynamic sql without granting select priv on sql query table Dan Guzman
6/9/2007 6:51:45 AM
Also, see http://www.sommarskog.se/grantperm.html.


--
Hope this helps.

Dan Guzman
SQL Server MVP

[quoted text, click to view]
AddThis Social Bookmark Button