SSIS事件处理程序 - 如何获取整个错误消息?

时间:2017-08-22 05:22:25

标签: ssis

我已经设置了一个数据流任务,其中包含一个源组件(ODBC to Salesforce),它将行计数和任何引发的错误消息写入表中。

我创建了一个OnError事件处理程序,它将System :: ErrorDescription中的消息写入变量,然后将该变量写入表中。

我的问题是System :: ErrorDescription没有有趣的错误消息,但摘要。 这些是在“进度”选项卡中生成的消息:

  • [SRC - Extract Account [6]]错误:System.Data.Odbc.OdbcException(0x80131937):ERROR [HY000] INVALID_LOGIN:用户名,密码,安全令牌无效;或用户锁定out.etc等等
  • [SSIS.Pipeline]错误:SRC - 提取帐户未能执行预执行阶段并返回错误代码0x80131937。

System :: ErrorDescription只有[SSIS.Pipeline]错误(" SRC - 提取帐户在预执行阶段失败并返回错误代码0x80131937")。 如何返回更详细的[SRC - 提取帐户[6]]消息?

谢谢, 杰森

2 个答案:

答案 0 :(得分:0)

您也可以只查询您的SSISDB以获取错误。

使用event_name查找错误

试试这个:

/*  
:: PURPOSE
Show the Information/Warning/Error messages found in the log for a specific execution
:: NOTES
The first resultset is the log, the second one shows the performance
:: INFO
Author: Davide Mauri
Version: 1.1
:: VERSION INFO
1.0: 
First Version
1.1:
Added filter option on Message Source
Correctly handled the "NULL" filter on ExecutionId
*/
USE SSISDB
GO
/*
Configuration
*/
-- Filter data by execution id (use NULL for no filter)
DECLARE @executionIdFilter BIGINT = NULL;
-- Show only Child Packages or everyhing
DECLARE @showOnlyChildPackages BIT = 0;
-- Show only message from a specific Message Source
DECLARE @messageSourceName NVARCHAR(MAX)= '%'
/*
Implementation
*/
/*
Log Info
*/
SELECT * FROM catalog.event_messages em 
WHERE ((em.operation_id = @executionIdFilter) OR @executionIdFilter IS NULL) 
AND (em.event_name IN ('OnInformation', 'OnError', 'OnWarning'))
AND (package_path LIKE CASE WHEN @showOnlyChildPackages = 1 THEN '\Package' ELSE '%' END)
AND (em.message_source_name like @messageSourceName)
ORDER BY em.event_message_id;
/*
Performance Breakdown
*/
IF (OBJECT_ID('tempdb..#t') IS NOT NULL) DROP TABLE #t;
WITH 
ctePRE AS 
(
SELECT * FROM catalog.event_messages em 
WHERE em.event_name IN ('OnPreExecute')
AND ((em.operation_id = @executionIdFilter) OR @executionIdFilter IS NULL)
AND (em.message_source_name like @messageSourceName)
), 
ctePOST AS 
(
SELECT * FROM catalog.event_messages em 
WHERE em.event_name IN ('OnPostExecute')
AND ((em.operation_id = @executionIdFilter) OR @executionIdFilter IS NULL)
AND (em.message_source_name like @messageSourceName)
)
SELECT
b.operation_id,
from_event_message_id = b.event_message_id,
to_event_message_id = e.event_message_id,
b.package_path,
b.execution_path,
b.message_source_name,
pre_message_time = b.message_time,
post_message_time = e.message_time,
elapsed_time_min = DATEDIFF(mi, b.message_time, COALESCE(e.message_time, SYSDATETIMEOFFSET()))
INTO
#t
FROM
ctePRE b
LEFT OUTER JOIN
ctePOST e ON b.operation_id = e.operation_id AND b.package_name = e.package_name AND b.message_source_id = e.message_source_id AND b.[execution_path] = e.[execution_path]
INNER JOIN
[catalog].executions e2 ON b.operation_id = e2.execution_id
WHERE
e2.status IN (2,7)
OPTION
(RECOMPILE)
;

答案 1 :(得分:0)

我知道这个问题很旧,但是今天我遇到了这个问题。 每个错误消息行都会触发OnError事件。 因此,要捕获所有错误行,请串联您的变量的值。 像这样: Dts.Variables["MyErrorVar"].Value = Dts.Variables["MyErrorVar"].Value + Environment.NewLine + Dts.Variables["System::ErrorDescription"].Value.ToString()