首页 > 解决方案 > 如何在 SSISDB 中将可执行错误作为消息公开

问题描述

我们目前正在从作为夜间批处理作业的一部分运行的 SSIS 执行进程任务中调用使用 python 构建的可执行文件。这一切都很好,但是当可执行文件失败时,只会引发一个非常基本的通用错误消息,而不会引用真正的底层错误。当可执行文件通过命令行运行时,底层错误正确返回。

无论如何,当通过 SSIS 执行过程任务调用并将其写入或记录到 SSISDB 目录时,我们是否可以冒泡可执行文件的潜在错误?

请参阅下面的现有错误以及应返回的理想错误(当前从命令行运行时返回)。

在此处输入图像描述

在此处输入图像描述

标签: sql-serverssisexeexecutablessis-2014

解决方案


Execute Process Task 上没有可用的选项,该选项将在失败时重定向输出并将其重新显示在日志记录中。

为此,您需要:

  • 定义一个变量来捕获输出
  • 在 Execute Process Task 的 StandardOutputVariable 选项中设置它
  • 在该任务的事件处理程序下,创建一个“OnTaskFailed”事件处理程序并使用脚本任务返回输出

例子:

名为“User::exe_output”的字符串变量,然后在执行进程任务中添加 StandardOutputVariable: 在此处输入图像描述

文档指出:

StandardOutputVariable选择一个变量来捕获流程的输出,或单击以创建一个新变量。

然后在事件处理程序下:

  • 在执行流程任务上添加“OnTaskFailed”事件
  • 添加脚本任务

在此处输入图像描述

打开脚本任务并将“User::exe_output”变量添加为 ReadOnlyVaraibles:

在此处输入图像描述

编辑脚本并添加以下代码:

public void Main()
{
    //Just assigning the exe_output to a local variable
    string exe_error = Dts.Variables["User::exe_output"].Value.ToString();

    //Checking it its blank
    if (exe_error != "")
    {
        //This brings back out whatever was captured in the output of the execute process task.
        //Depending on how you want it logged, warning or an error, either one will log the output.

        //Dts.Events.FireError(-1, "Execute Process Task Error", exe_error, String.Empty, 0);
        Dts.Events.FireWarning(-1, "Execute Process Task Error", exe_error, String.Empty, 0);
    }
    Dts.TaskResult = (int)ScriptResults.Success;
}

然后,当流程运行并失败时,您仍然会收到原始消息,但现在您还可以获得从 Execute Process Task 的输出中捕获的内容:

在此处输入图像描述

在我的示例中,我只是试图复制一个不存在的文件。


推荐阅读