以下是我如何从通过 SQL 代理作业调用的 SSIS 包管理跟踪“返回状态”。如果我们幸运的话,其中一些可能适用于您的系统。
...然后它变得一团糟,因为您可以获得从 SSIS 返回的大量值。在执行 SSIS 步骤时,我在数据库表中记录了操作和活动,并查阅了该表以尝试解决问题(这就是下面的 @Description 的来源)。以下是相关代码和注释:
-- Evaluate the DTEXEC return code
SET @Message = case
when @ReturnValue = 1 and @Description <> 'SSIS Package' then 'SSIS Package execution was stopped or interrupted before it completed'
when @ReturnValue in (0,1) then '' -- Package success or failure is logged within the package
when @ReturnValue = 3 then 'DTEXEC exit code 3, package interrupted'
when @ReturnValue in (4,5,6) then 'DTEXEC exit code ' + cast(@Returnvalue as varchar(10)) + ', package could not be run'
else 'DTEXEC exit code ' + isnull(cast(@Returnvalue as varchar(10)), '<NULL>') + ' is an unknown and unanticipated value'
end
-- Oddball case: if cmd.exe process is killed, return value is 1, but process will continue anyway
-- and could finish 100% succesfully... and @ReturnValue will equal 1. If you can figure out how,
-- write a check for this in here.
最后提到“如果在 SSIS 运行时,一些管理员小丑杀死了 CMD 会话(例如,来自 taskmanager),因为进程运行时间过长”的情况。我们从来没有发生过——据我所知——但当我写这篇文章时,他们非常偏执,所以我不得不调查一下……