I was strolling along one day when I saw somebody asking how to find out who owns a maintenance plan. That evolved into finding out who owns the the job associated with the maintenance plan. All of this in SQL 2005 and SQL 2008.
Well, we were stumped for a bit trying to figure the link between the job tables in the msdb database and the ssis table in the same database. Linking the two together is not very obvious and we struggled with it for a bit. After some research and trying this that and the other, I was able to come up with the below script.
-- Display SSIS Package Owners and Job Owners SQL 2008
,p.name As PackageOwner
,JOB.name as JobOwner
when 0 then 'default value'
When 1 Then 'SQL Server Import and Export Wizard'
When 2 Then 'DTS Designer in SQL Server 2000'
When 3 Then 'SQL Server Replication'
When 5 Then 'SSIS Designer'
When 6 Then 'Maintenance Plan Designer or Wizard'
From msdb.dbo.sysssispackages dts
Left Join master.sys.server_principals p
On p.sid = dts.ownersid
Left Outer Join msdb.dbo.sysjobsteps SJS
On dts.name = substring(SJS.command,CHARINDEX('\',sjs.command)+1,charindex('"',sjs.command,CHARINDEX('\',sjs.command))-CHARINDEX('\',sjs.command)-1)
And SJS.subsystem = 'ssis'
Left Outer Join msdb.dbo.sysjobs SJ
On SJS.job_id = SJ.job_id
Left Outer Join master.sys.server_principals JOB
On JOB.sid = SJ.owner_sid
This script is set to work out of the gate with SQL 2008. Should you want it to work with SQL 2005 the change is simple. Change the sysssispackages table to sysdtspackages90. As you can see, the query joins the SSIS table to the jobsteps table with a pretty nasty string extraction. There are other ways of extracting this information (I’m sure of it). This works quite well for what it is intended.
Using this script, you can find out the jobowner, the packageowner, and the packagetype. This is pretty good information to have on hand if you have several ssis packages that are stored in msdb and are run from a job. One thing this script does not yet handle is if the SSIS file is stored on the file system. Note that I only coded it so far to work with files stored in SQL. When looking in the jobsteps table, you can tell the difference quickly by seeing that those stored in msdb have a /SQL at the beginning of the command string. Those in the filesystem have a /FILE en lieu of that /SQL.
In a future revision I will work on parsing the package name out of that string that represents those stored in the file system. And despite that nasty join, this runs quickly on my systems. I am open to suggestions or other solutions that can provide this kind of insight.