0

运行 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 

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

在此先感谢,罗尼。

4

2 回答 2

0

查看 SQL 作业属性窗口中的通知选项卡。

于 2012-08-20T09:46:10.440 回答
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
于 2012-09-17T09:51:47.857 回答