Automatically change the Owner on SQL Agent job

  • We have a number of maintenance plans built in Management Studio. We change the owner on the Agent jobs that run the maintenance plans to a be a "AgentService" login so all our Agent jobs run under this one global login (each server has their own). But whenever I change a maintenance plan, the owner of the Agent job changes. I need to remember to change each step back to the "AgentService" owner.

    First of all, is there a way to change this so the Owner stays intact? Second, if not, does anybody know why SQL Server has this built in their system this way? It drives me crazy.

    Thanks for your help!

  • You can use these two snippets, I got them from a bog I believe:

    --SQL 2005

    UPDATE msdb.dbo.sysdtspackages90

    SET ownersid = 0x01

    where packagetype = 6

    --SQL 2008

    UPDATE msdb.dbo.sysssispackages

    SET [ownersid] = SUSER_SID('sa')

    where packagetype = 6

    Andrew

  • Thank you! This is a huge help. I am posting the little script I wrote (for SQL2005) for anyone's additional reference.

    --To view all the packages and their owners.

    SELECT dts.name AS package_name

    ,SUSER_SNAME(dts.ownersid) AS package_owner

    FROMmsdb.dbo.sysdtspackages90 dts

    ORDER BY package_name

    --To view all the info on the maintenance plans

    SELECT*

    FROMmsdb.dbo.sysdtspackages90

    WHEREpackagetype = 6

    --Find out the OwnersId for the login you want to use.

    SELECTloginname, sid

    FROMsyslogins

    --To Update the owner

    UPDATE msdb.dbo.sysdtspackages90 SET

    ownersid = 0x0105000000000005150000000421C9C7B2AB5D056CCD5020D82A0000--Copy/Pasted from above script

    --WHEREname = 'UserBackup'--Change a specific SSIS package

    WHEREpackagetype = 6--To change all maintenance plans

Viewing 3 posts - 1 through 2 (of 2 total)

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