Users scheduling jobs

  • 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!

  • 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?

    [font="Times New Roman"]Erland Sommarskog, SQL Server MVP, www.sommarskog.se[/font]

  • 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, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • 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'?

  • 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.

    [font="Times New Roman"]Erland Sommarskog, SQL Server MVP, www.sommarskog.se[/font]

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply