获取 SQL 服务器代理作业,该作业具有 运行 已部署 SSIS 包的特定执行

Get the SQL Server Agent job that has run a particular execution of a deployed SSIS package

我在 SQL 服务器中部署了一个 SSIS 程序包,并且有 3 个不同的 SQL 服务器代理作业 运行 在不同的步骤和计划中使用此程序包。

我的问题是:如果包在 Integration Services Catalogues -> Reports 中显示为失败,有没有一种方法可以识别 运行 执行哪个作业导致包失败(不是通过作业历史记录的失败时间和包失败执行时间交叉检查)?

这不是很直接。基于this stack exchange answer,你可以尝试:

SELECT 
 history.*
,ex.* 
,ex.status
, CASE ex.status
    WHEN 1 THEN 'created'
    WHEN 2 THEN 'running'
    WHEN 3 then 'canceled'
    WHEN 4 then 'failed'
    WHEN 5 then 'pending'
    WHEN 6 then 'ended unexpectedly'
    WHEN 7 then 'succeeded'
    WHEN 8 then 'stopping'
    WHEN 9 then 'completed'
END as job_status
FROM (
    SELECT 
        h.step_name,  
        -- h.message, 
        h.run_status, 
        h.run_date, 
        h.run_time, 
        SUBSTRING(h.message, NULLIF(CHARINDEX('Execution ID: ', h.message),0)+14 ,PATINDEX('%[^0-9]%',SUBSTRING(h.message, NULLIF(CHARINDEX('Execution ID: ', h.message),0)+14 ,20))-1) ExecutionId
    FROM MSDB.DBO.SYSJOBHISTORY h) history
LEFT JOIN 
SSISDB.CATALOG.EXECUTIONS ex on ex.execution_id = history.ExecutionId
WHERE project_name = '<ssisdb_project_name_here>'

它有很多列,您可以通过替换 select 中的 * 来忽略这些列。重要的部分是加入 MSDB.DBO.SYSJOBHISTORYMSDB.DBO.SYSJOBHISTORY

此外,这适用于项目部署模式,不适用于 SSIS 的包部署模式。