正确的SSIS作业错误消息

时间:2012-08-20 09:39:51

标签: sql-server sql-server-2008 ssis

运行SSIS包的作业有时会在我们的环境中失败。

查找作业历史记录中的实际错误消息有点令人恼火。 例如,错误:“ 登录超时已过期 ”隐藏在所有这些字词中:

Executed as user: ****** Microsoft (R) SQL Server Execute Package Utility  Version 10.0.2531.0 for 64-bit  Copyright (C) Microsoft Corp 1984-2005. All rights reserved.    Started:  8:31:01  Error: 2012-07-18 08:31:20.95     Code: 0xC0202009     Source: ***** Description: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.  An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 10.0"  Hresult: 0x80004005  Description: "Login timeout expired".  An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 10.0"  Hresult: 0x80004005  Description: "Unable to complete login process due to delay in login response".  An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 10.0"  Hresult: 0x80004005  Description: "TCP Provider: Timeout error [258]. ".  End Error  Error: 2012-07-18 08:31:20.98     Code: 0xC020801C     Source: **** Description: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER.  The AcquireConnection method call to the connection manager **** failed with error code 0xC0202009.  There may be error messages posted before this with more information on why the AcquireConnection method call failed.  End Error  Error: 2012-07-18 08:31:20.99     Code: 0xC0047017     Source: Find and send notifications SSIS.Pipeline     Description: component "Duplicate contracts" (3002) failed validation and returned error code 0xC020801C.  End Error  Error: 2012-07-18 08:31:20.99     Code: 0xC004700C     Source: Find and send notifications SSIS.Pipeline     Description: One or more component failed validation.  End Error  Error: 2012-07-18 08:31:21.00     Code: 0xC0024107     Source: Find and send notifications      Description: There were errors during task validation.  End Error  DTExec: The package execution returned DTSER_FAILURE (1).  Started:  8:31:01  Finished: 8:31:21  Elapsed:  19.984 seconds.  The package execution failed.  The step faile 

您是否碰巧知道在作业历史记录中查看/获取/接收/检测错误消息的任何其他方式(更方便)?

提前致谢, 罗尼。

2 个答案:

答案 0 :(得分:0)

在SQL Job的属性窗口中查看“通知”选项卡。

答案 1 :(得分:0)

最后,我们创建了一个与包同步运行的作业,并检查作业是否在最后5分钟内失败。 如果是这样,它将发送错误消息。

附上请找代码。 您需要做的就是更改“ProfileName”和邮件本身。

    select
 j.name,h.step_name, message, run_status,run_date,run_time,run_duration
into
 ##tCheck
from
 msdb..sysjobhistory h
inner
 join msdb..sysjobs j
on h.job_id = j.job_id
and
 run_status=0
and
 run_date = CONVERT(varchar(10),getdate(),112)--Looking on failed job from today.
and
 run_time > cast (replace(CONVERT(varchar(10),dateadd(mi,-5,getdate()),108),':','')as int)   --Looking on failed job from the last 5 minutes.
and
 step_name<>'(Job outcome)'
order
 by h.run_date desc ,h.run_time desc 

if
 @@rowcount > 0
begin
DECLARE
 @xml NVARCHAR(MAX)
DECLARE
 @body NVARCHAR(MAX)

SET
 @xml = CAST(( SELECT name AS 'td','' 
,step_name AS 'td',''
,message AS 'td',''
,run_status AS 'td',''
,run_Date AS 'td',''
,run_time AS 'td',''
,run_duration AS 'td'
FROM
  ##tCheck ORDER BY name 
FOR
 XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))

SET
 @body ='<html><body><H3>Job Failed message</H3><table border = 1> <tr><th> name </th> <th> step_name Name </th> <th> message </th> <th> run_status </th><th> run_Date </th><th> run_time </th> <th> run_duration </th></tr>'     
SET
 @body = @body + @xml +'</table></body></html>'
EXEC
 msdb.dbo.sp_send_dbmail
@profile_name = '<profile_name>',
 @recipients 
= '<email>',
 @subject 
= 'Failed job details' ,
 @body 
= @body, 
@body_format 
='HTML'

end

drop

 table ##tCheck


go