如何在 SSISDB 中将可执行错误作为消息公开
How to expose an executable error as a message in SSISDB
我们目前正在从 SSIS 执行进程任务 运行 中调用使用 python 构建的可执行文件,作为夜间批处理作业的一部分。这一切都很好,但是当可执行文件失败时,只会引发非常基本的一般错误消息,而不会引用真正的底层错误。当可执行文件通过命令行 运行 时,底层错误正确 returns.
当通过 SSIS 执行进程任务调用时,我们是否可以冒出可执行文件的底层错误并将其写入或记录到 SSISDB 目录?
请查看下面的现有错误以及应该返回的理想错误(当前从命令行 运行ning 时返回)。
执行进程任务上没有可用的选项,可以在失败时重定向输出并在日志记录中恢复输出。
要做到这一点,您需要:
- 定义了一个变量来捕获输出
- 在执行进程任务的 StandardOutputVariable 选项中进行设置
- 在该任务的事件处理程序下,创建一个 "OnTaskFailed" 事件处理程序并使用脚本任务 return 取消输出
示例:
名为 "User::exe_output" 的字符串变量,然后在执行流程任务中添加 StandardOutputVariable:
documentation 状态:
StandardOutputVariable Select a variable to capture the output of the
process, or click to create a new variable.
然后在事件处理程序下:
- 在执行进程任务上添加一个 "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;
}
然后,当流程运行失败时,您仍然会收到原始消息,但现在您还会收到从执行流程任务的输出中捕获的内容:
在我的示例中,我只是试图复制一个不存在的文件。
我们目前正在从 SSIS 执行进程任务 运行 中调用使用 python 构建的可执行文件,作为夜间批处理作业的一部分。这一切都很好,但是当可执行文件失败时,只会引发非常基本的一般错误消息,而不会引用真正的底层错误。当可执行文件通过命令行 运行 时,底层错误正确 returns.
当通过 SSIS 执行进程任务调用时,我们是否可以冒出可执行文件的底层错误并将其写入或记录到 SSISDB 目录?
请查看下面的现有错误以及应该返回的理想错误(当前从命令行 运行ning 时返回)。
执行进程任务上没有可用的选项,可以在失败时重定向输出并在日志记录中恢复输出。
要做到这一点,您需要:
- 定义了一个变量来捕获输出
- 在执行进程任务的 StandardOutputVariable 选项中进行设置
- 在该任务的事件处理程序下,创建一个 "OnTaskFailed" 事件处理程序并使用脚本任务 return 取消输出
示例:
名为 "User::exe_output" 的字符串变量,然后在执行流程任务中添加 StandardOutputVariable:
documentation 状态:
StandardOutputVariable Select a variable to capture the output of the process, or click to create a new variable.
然后在事件处理程序下:
- 在执行进程任务上添加一个 "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;
}
然后,当流程运行失败时,您仍然会收到原始消息,但现在您还会收到从执行流程任务的输出中捕获的内容:
在我的示例中,我只是试图复制一个不存在的文件。