Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Users scheduling jobs Expand / Collapse
Author
Message
Posted Monday, July 21, 2014 12:14 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Yesterday @ 5:30 AM
Points: 430, Visits: 963
Is there a way to allow users to schedule a job that they don't own?

If I'm reading it right -- and I now think I maybe am not -- Books Online seems to suggest they should be able to create a schedule for a job they don't own, as long as they're members of the msdb SQLAgentOperatorRole DB role (in fact it looks like the SQLAgentUserRole should be able to do it, but...)

So I added my users' AD group / DB user to the SQLAgentOperatorRole DB role. But when I call sp_add_jobschedule, I get "Only members of sysadmin role are allowed to update or delete jobs owned by a different login." -- which is not what I'm trying to do, I just want to create a new schedule for the job.

I tried changing the owner to the AD group through which my users connect, but it doesn't allow Windows groups to be job owners, only user logins.

I also tried EXECUTE AS, but get permission problems, and I'm not sure I want to begin traveling the impersonation road.

Thanks for any help on this!



Post #1594747
Posted Monday, July 21, 2014 2:59 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 7:07 AM
Points: 803, Visits: 720
This article on my web site includes examples for a related problem - having users to start a specific job,
http://www.sommarskog.se/grantperm.html. Maybe it can serve as inspiration?


Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Post #1594840
Posted Monday, July 21, 2014 3:39 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 10:58 PM
Points: 21,755, Visits: 15,461
Do the users need to be able to change the schedule of existing jobs or do they need to be able to kick off the job (some people refer to this as scheduling a job)?





Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1594853
Posted Tuesday, July 22, 2014 6:44 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Yesterday @ 5:30 AM
Points: 430, Visits: 963
Hi Erland,

They only need to be able to create a new schedule for an existing job. Essentially, I want them to be able to call a stored proc at the time of their choosing.

I read your article -- very informative. I've added it to my bookmarks, right beside your article on dynamic SQL, to which I've referred many a time over the years.

So what I've done -- which works -- is:
1) Create the sproc in the user DB WITH EXECUTE AS SELF.
By my understanding, this should be me. But...
2) Grant execute to the DB group to which the the users belong.

Now, when I call the sproc using EXECUTE AS <one of the users>, and do a SELECT SUSER_SNAME(), it returns the database owner -- which is not me?? In the same query window, but outside the stored procedure, SELECT SUSER_SNAME() returns my account.

I also tried creating the sproc WITH EXECUTE AS 'Domain\database owner account', but I get an error, as that login does not explicitly exist - it's a member of an AD group that has sa privs. It's also the account under which the SQL Server service operates. I would have expected this to work, however.

Finally, I tried WITH EXECUTE AS 'Domain\my account', and this also works. I'm a member of the same AD group as the 'Domain\database owner account'. So I wonder now:
1) how come SELF <> me
2) why it doesn't work when I specify the 'Domain\database owner account'?











Post #1595060
Posted Tuesday, July 22, 2014 2:39 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 7:07 AM
Points: 803, Visits: 720
Keep in mind that the EXECUTE AS clause specifies a database user. I assume that you are a member of sysadmin. In that case, your login maps to dbo in the database.

For the same reason, it does not work to specify EXECUTE AS 'domain\databaseowner', because there is no such user in the database - or least I would not expect so. The login 'domain\databaseowner' maps to dbo.


Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Post #1595282
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse