【问题标题】:SSIS - Script Component - Change icon based on resultsSSIS - 脚本组件 - 根据结果更改图标
【发布时间】:2017-06-08 14:11:32
【问题描述】:

在我的 SSIS 脚本组件任务(不是脚本任务,它可以添加到控制流中,而是脚本组件任务,它添加到数据流中)中,我在 @ 的 catch 部分添加了一些错误处理987654324@块:

// No connection was created. Exit gracefully
bool cancelOnError = false;
ComponentMetaData.FireError(ErrorCode: 10, SubComponent: "SubComponent", 
Description: "Couldn't set up the connection. This could be because an invalid host was 
provided, or due to a firewall blocking the connection.", HelpFile: "", HelpContext: 0, 
pbCancel: out cancelOnError);

这一切都很好,脚本任务捕获了我在代码中提出的错误。我还可以在日志中看到错误:

Error: 0xA at DFT Extract, SubComponent: Couldn't set up the connection. 
This could be because an invalid host was provided, or due to a firewall 
blocking the connection.

但是,任务上的图标是绿色的,并且我定义的用于处理结果的后续任务被触发(但没有什么要处理的,因为此特定错误发生在处理任何数据之前):

数据流正确显示了一个红十字图标。有什么方法可以更改脚本组件上的图标,或者有更好的方法让我(优雅地)模拟一个显示停止错误?

我找到了this page on Microsoft,显示了Script Task和Script Components的区别,其中还说明了:

脚本组件作为数据流任务的一部分运行,并不 使用这些属性之一报告结果。

这并没有让我很有希望,但我希望有人可以解决这个问题。我主要认为当我们捕获错误时显示绿色图标有点误导。

【问题讨论】:

    标签: sql-server error-handling ssis etl


    【解决方案1】:

    为什么不直接将 cancelonerror 值更改为 true

    bool cancelOnError = true;
    

    或者你可以使用Throw exception方法

    throw new Exception("Couldn't set up the connection. This could be because an invalid host was 
    provided, or due to a firewall blocking the connection.");
    

    解决方法

    如果您的目标是忽略未正确处理的行,最好的方法是在OutputBuffer(DT_BOOL 类型)中添加一个列,如果出现错误,则将此列值设置为False,否则它的值必须是True

    并在脚本组件后添加条件拆分,以根据此列过滤行。用类似的表达方式:

    [FlagColumn] == True
    

    【讨论】:

    • 感谢您的建议。我之前尝试设置为True,但并没有真正注意到任何区别。我主要担心这意味着我正确处理的任何内容都可能不会发送到输出(我们从队列中获取消息,一旦它们离开队列,我们​​将不会再看到它们,因此确保它们通过正确对我们至关重要)。不过,我可以很快尝试一下 Exception。谢谢你的建议:)
    • @SchmitzIT 我添加了一个解决方法,它可能会帮助你,检查我的答案更新
    猜你喜欢
    • 1970-01-01
    • 2017-04-29
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 2014-07-04
    • 1970-01-01
    • 1970-01-01
    • 2011-04-16
    相关资源
    最近更新 更多