SQL消息输出在SSIS中显示为错误

时间:2015-10-12 18:56:36

标签: sql ssis business-intelligence ssis-2012 ssis-2008

因此,无论何时查询执行失败,我的SSIS包都会将查询执行中的消息记录为错误。因此,例如我的查询有2个Print语句,由于某些原因查询因某些错误而失败。 SSIS记录所有2个打印语句以及实际错误。我不希望SSIS包将打印消息记录为错误。我的包正在读取" OnError"事件处理程序并且日志的源设置为:System :: ErrorDescription。请考虑以下查询:

PRINT 'Trying to set string value to a datetime column.'
PRINT 'So i should get this error: Conversion failed when converting date and/or time from character string.'
UPDATE TempTable SET CreateDateTime = 'StringValue'

以下是SQL Management Studio的输出/消息。最后一行是实际错误,其余行都是打印语句。

Trying to set string value to a datetime column.
So i should get this error: Conversion failed when converting date and/or time from character string.

**Msg 3930, Level 16, State 1, Procedure pr_TempTable, Line 3 Conversion failed when converting date and/or time from character string.**

但是当我尝试执行SQL任务并运行此查询时,SSIS中的OnError事件处理程序将消息窗口中的所有这三行视为多个错误。

1 个答案:

答案 0 :(得分:2)

起初,我怀疑你实际上是用“RAISERROR”“打印”你的陈述,这是一种相当常见的做法。

然而,在进一步研究中,我发现PRINT命令似乎是标准行为,它包含在由后续RAISERROR在同一脚本中发送给调用应用程序的错误消息中。

因此,如果您不在脚本中使用RAISERROR,则SSIS不会将PRINT语句视为错误。但是如果你确实使用了RAISERROR,那么在RAISERROR之前发生的任何PRINT语句都将包含在引发的错误消息中。

这很奇怪而且远非直观,但它似乎是标准行为,看起来你只需要解决它。