﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Administering / SQL Server 2005  / Dynamic SQL, Ownership Chaining, and EXECUTE AS / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 22 May 2013 01:41:31 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Dynamic SQL, Ownership Chaining, and EXECUTE AS</title><link>http://www.sqlservercentral.com/Forums/Topic1395858-146-1.aspx</link><description>[quote][b]kramaswamy (12/13/2012)[/b][hr]Interesting - so for cross-database calls, this approach will not work? In which case, what will need to be done - the calling login will have to have access to the tables on the other database? Or will it just be the EXECUTE AS login that will need access to the tables on the other database?[/quote]If you try to use EXECUTE AS LOGIN you start running into impersonation issues. The cleanest way to support that in my opinion is to sign the module with a certificate linked to a login that has access to do everything required in the instance, i.e. what is required across various databases.</description><pubDate>Thu, 13 Dec 2012 11:19:54 GMT</pubDate><dc:creator>opc.three</dc:creator></item><item><title>RE: Dynamic SQL, Ownership Chaining, and EXECUTE AS</title><link>http://www.sqlservercentral.com/Forums/Topic1395858-146-1.aspx</link><description>Interesting - so for cross-database calls, this approach will not work? In which case, what will need to be done - the calling login will have to have access to the tables on the other database? Or will it just be the EXECUTE AS login that will need access to the tables on the other database?</description><pubDate>Thu, 13 Dec 2012 11:04:44 GMT</pubDate><dc:creator>kramaswamy</dc:creator></item><item><title>RE: Dynamic SQL, Ownership Chaining, and EXECUTE AS</title><link>http://www.sqlservercentral.com/Forums/Topic1395858-146-1.aspx</link><description>[quote][b]jeetsingh.cs (12/13/2012)[/b][hr]See you can also try to give access permission on master and grant on sp_executesql..[/quote]That is not likely to help. All server logins automatically get a database user created for them in master and all users in master have execute permissions on sp_executesql. The issue is likely not the lack of permissions to execute sp_executesql itself, it's likely the lack of permissions of the user in the user-database that is executing the user-proc that calls sp_executesql to access the resources used by the dynamic sql submitted to sp_executesql.</description><pubDate>Thu, 13 Dec 2012 09:48:19 GMT</pubDate><dc:creator>opc.three</dc:creator></item><item><title>RE: Dynamic SQL, Ownership Chaining, and EXECUTE AS</title><link>http://www.sqlservercentral.com/Forums/Topic1395858-146-1.aspx</link><description>See you can also try to give access permission on master and grant on sp_executesql..</description><pubDate>Thu, 13 Dec 2012 00:49:15 GMT</pubDate><dc:creator>jeetsingh.cs</dc:creator></item><item><title>RE: Dynamic SQL, Ownership Chaining, and EXECUTE AS</title><link>http://www.sqlservercentral.com/Forums/Topic1395858-146-1.aspx</link><description>I use option 2 all the time using a login-less Database User. This way the procedure executes as a Database User with elevated permissions but no one can ever connect to the database as that user directly meaning it only exists for purposes of running dynamic SQL. This technique only works however if you are only making calls to tables within the same database, i.e. not doing any cross-database calls in your Dynamic SQL.[code="sql"]USE [YourDatabase];GOCREATE USER [DynamicSqlRunner] WITHOUT LOGIN;GOCREATE PROC dbo.WhateverProc (@ParameterName VARCHAR(100))WITH EXECUTE AS 'DynamicSqlRunner'ASBEGIN    -- proc code goes here    SELECT 1ENDGO[/code]</description><pubDate>Thu, 13 Dec 2012 00:38:26 GMT</pubDate><dc:creator>opc.three</dc:creator></item><item><title>Dynamic SQL, Ownership Chaining, and EXECUTE AS</title><link>http://www.sqlservercentral.com/Forums/Topic1395858-146-1.aspx</link><description>Hi all,I've got a procedure which is using dynamic SQL to construct an SQL statement, and then execute the statement using sp_ExecuteSQL.I've given permission to the login to execute the stored procedure - but, since I'm using sp_ExecuteSQL, it is failing, due to the fact that the login does not have permissions on the underlying table.As far as my research has told me, there are two solutions to the problem:1) Grant the user permissions to each underlying table. This means SELECT, and possibly INSERT AND DELETE depending on what the dynamic SQL is supposed to do.2) Create the procedure with EXECUTE AS, and use a different login that has permissions on the underlying tables.Seems to me like option #2 is the better choice, but I'd like to know if there are any risks associated. It seems to me that there shouldn't - all the login has permission to do is execute the stored procedure that I've given it access to.</description><pubDate>Wed, 12 Dec 2012 13:00:33 GMT</pubDate><dc:creator>kramaswamy</dc:creator></item></channel></rss>