Groups | Blog | Home
all groups > sql server programming > october 2004 >

sql server programming : Dynamic SQL and ownership chaining



vtuomola NO[at]SPAM gmail.com
10/12/2004 11:58:25 PM
Hi all,

I would like to have stored procedures that select data from another
database without granting the user running the proc access to the
other db.

It works fine until I have procs which contain dynamic SQL as it
breaks the ownership chain. Is there a way to circumvent this
without granting the user access to the other db (no, I don't want to
rewrite the dynamic sql to non-dynamic;)?

Regards,

Wayne Snyder
10/13/2004 8:24:05 AM
An exec statement does NOT run under the same security as the SP does using
the same ownership chain ( it is a separate batch).

ALthough I haven't tried this, you might try to add an SP on the OTHER
server which accepts a query string and exec it on the other server... I
don't if it would work, but it wouldn't take long for you to find out..

You might also try using sp_executsql, which probably would work... Try
replacing your exec statement with sp_executesql... It is doc'd in books on
line...

I hope this works for you!....


--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)

I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org

[quoted text, click to view]

vtuomola NO[at]SPAM gmail.com
10/20/2004 1:07:33 AM
Thanks for your help,

I solved this by porting my dynamic sql to several static statements
and a lot of if-else structures :)

In SQL Server 2005 this problem is solved by execution context, but
for now there seems to be no easy solution to the problem.

-Ville

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