SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


With Execute AS


With Execute AS

Author
Message
dwilliscp
dwilliscp
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5226 Visits: 813
We moved our application over from 2008R2.... set up the sysadmin Active Directory group.. but the below code no longer works.

I even commented out the sp_delete_job and had it do a simple select..

ALTER PROCEDURE [dbo].[DeleteJob]


@Name nvarchar(260)

WITH EXECUTE AS 'Domain\DB' --This needs to be uncommented and a proper sysadmin user added that is a dbo in msdb.

AS

print 'hi'

select * from msdb.dbo.sysjobs

---- exec msdb.dbo.sp_delete_job @job_name = @name


What I get is :

hi

Msg 229, Level 14, State 5, Procedure DeleteJob, Line 166

The SELECT permission was denied on the object 'sysjobs', database 'msdb', schema 'dbo'.



However when I go into msdb and run the select.. it works... and I am part of Domain\DB

Sue_H
Sue_H
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: General Forum Members
Points: 36008 Visits: 10285
dwilliscp - Thursday, February 8, 2018 2:19 PM
We moved our application over from 2008R2.... set up the sysadmin Active Directory group.. but the below code no longer works.

I even commented out the sp_delete_job and had it do a simple select..

ALTER PROCEDURE [dbo].[DeleteJob]


@Name nvarchar(260)

WITH EXECUTE AS 'Domain\DB' --This needs to be uncommented and a proper sysadmin user added that is a dbo in msdb.

AS

print 'hi'

select * from msdb.dbo.sysjobs

---- exec msdb.dbo.sp_delete_job @job_name = @name


What I get is :

hi

Msg 229, Level 14, State 5, Procedure DeleteJob, Line 166

The SELECT permission was denied on the object 'sysjobs', database 'msdb', schema 'dbo'.



However when I go into msdb and run the select.. it works... and I am part of Domain\DB


If you check the information on the arguments in the documentation for Execute As, it states:
name must be a singleton account, and cannot be a group, role, certificate, key, or built-in account, such as NT AUTHORITY\LocalService, NT AUTHORITY\NetworkService, or NT AUTHORITY\LocalSystem.
EXECUTE AS (Transact-SQL)

Sue



dwilliscp
dwilliscp
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5226 Visits: 813
Thanks for the help.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search