C# 如何在SSIS中为父包和子包设置OneError事件
我使用的是2016版本,有一个主ETL_提取包,其中我使用执行包任务执行三个子包(ABC、DEF、XYZ)。我想捕获C# 如何在SSIS中为父包和子包设置OneError事件,c#,ssis,event-handling,C#,Ssis,Event Handling,我使用的是2016版本,有一个主ETL_提取包,其中我使用执行包任务执行三个子包(ABC、DEF、XYZ)。我想捕获System::Error\u Description以了解这些子包中发生的任何错误,并且必须通过父包以电子邮件形式通知 我正在使用子包上的OnError事件和下面的脚本来捕获子包上的“System::Error_Description”使用脚本任务,如下所示: 在子脚本任务中将以下系统变量用作只读: System::PackageName System::SourceName S
System::Error\u Description
以了解这些子包中发生的任何错误,并且必须通过父包以电子邮件形式通知
我正在使用子包上的OnError事件和下面的脚本来捕获子包上的“System::Error_Description”
使用脚本任务,如下所示:
在子脚本任务中将以下系统变量用作只读:
System::PackageName
System::SourceName
System::ErrorDescription
using System;
using System.Data;
using System.IO;
// build our the error message
string ErrorMessageToPassToParent = "Package Name: " + Dts.Variables["System::PackageName"].Value.ToString() + Environment.NewLine + Environment.NewLine +
"Step Failed On: " + Dts.Variables["System::SourceName"].Value.ToString() + Environment.NewLine + Environment.NewLine +
"Error Description: " + Dts.Variables["System::ErrorDescription"].Value.ToString();
// Populate collection of variables.
// This will include parent package variables.
Variables vars = null;
Dts.VariableDispenser.GetVariables(ref vars);
// Lock the variables.
Dts.VariableDispenser.LockForWrite("User::OnError_Description_FromChild");
Dts.VariableDispenser.GetVariables(ref vars);
vars["User::OnError_Description_FromChild"].Value = ErrorMessageToPassToParent;
vars.Unlock();
然后在父包ETL_Extract中,我声明了字符串变量“OnError_Description_FromChild”,并为ETL_Extract包设置OnError事件
在父包脚本任务中,我使用“OnError\u Description\u FromChild”作为只读变量。下面是父包脚本
// get the variable from the parent package for the error
string ErrorFromChildPackage = Dts.Variables["User::OnError_ErrorDescription_FromChild"].Value.ToString();
// do a check if the value is empty or not (so we know if the error came from the child package or occurred in the parent package itself
if (ErrorFromChildPackage.Length > 0)
{
// Then raise the error that was created in the child package
Dts.Events.FireError(0, "Capture Error From Child Package Failure",
ErrorFromChildPackage
, String.Empty, 0);
} // end if the error length of variable is > 0
我是C#初学者,但从stackoverflow中获得的关于上述逻辑编码的参考很少。当我在一个子包上执行带有一些错误条件的父包时,这里发生的事情很少
首先,foreach循环容器内的子包发生错误,子包脚本任务执行多次
第二,当脚本任务在子包上完成时,它不会在父包的错误事件中触发,而父包也会失败。
我不知道为什么OneError事件没有在父包上触发。
我一直在寻找有关如何访问父包中的子包变量的信息。你说的“它不工作”是什么意思?您在尝试链接问题中的解决方案时是否出现错误?@digital.aron-我已经按照建议添加了一些详细信息。感谢当一个子包点击Foreach循环并触发多个错误时,父包和子包的预期行为是什么?如果孩子遇到错误,是否应该继续循环?由于子Foreach循环错误,父级是否应发送多封电子邮件?另外,您能告诉我们事件处理程序是如何配置的吗?它现在没有循环。我已使用脚本组件设置OneError事件,以捕获子包的错误消息,并使用脚本组件和电子邮件任务在父包设置OneError事件。当子包失败时,它会触发onerror事件,稍后父包也会失败,但它不会触发onerror事件。