【问题标题】:SSIS when child package fails pass FULL error to parent package子包失败时的 SSIS 将 FULL 错误传递给父包
【发布时间】:2016-09-17 02:26:04
【问题描述】:

我有一个调用子包的父包。如果子包失败,则会显示子包的完整错误详细信息,但父包只会显示“任务执行包失败”。

如何让父包从子包中获取完整的错误消息,以便正确获取父包中的完整错误详细信息?

【问题讨论】:

    标签: ssis parent-child


    【解决方案1】:

    解决方案:

    如何从子包中获取错误详细信息。

    此解决方案将接受子包的任何错误并将错误消息传递给父包。然后父包将接收它收到的错误,并在父包执行结果中发布完整的详细信息。

    注意:逻辑是这样编写的,因此子包仍然可以自己运行(而不是作为子包),而不会因缺少父包中的变量名而出现任何错误。此外,如果您从父包运行子包但不想从子包中捕获错误,只需不包含变​​量名称或 OnError 事件处理程序,这样也不会因缺少变量而导致任何错误。

    1. 为整个子包创建了一个 OnError 事件处理程序。

    2. 将脚本任务添加到事件处理程序。

      一个。将只读变量传递给它:System::ErrorDescription,System::SourceName,System::PackageName

      b.在脚本任务中执行此操作(cmets 应详细说明它在做什么):

          // 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();
      
      
      
          // have to do this FIRST so you can access variable without passing it into the script task from SSIS tool box
          // populate collection of variables. This will include parent package variables.
          Variables vars = null;
          Dts.VariableDispenser.GetVariables(ref vars);
      
      
          // checks if this variable exists in parent first, and if so then will set it to the value of the child variable 
          //  (do this so if parent package does not have the variable it will not error out when trying to set a non-existent variable)
          if (Dts.VariableDispenser.Contains("OnError_ErrorDescription_FromChild") == true)
          {
      
              // Lock the to and from variables. 
              // parent variable
              Dts.VariableDispenser.LockForWrite("User::OnError_ErrorDescription_FromChild");
      
              // Need to call GetVariables again after locking them. Not sure why - perhaps to get a clean post-lock set of values.
              Dts.VariableDispenser.GetVariables(ref vars);
      
              // Set parentvar = childvar
              vars["User::OnError_ErrorDescription_FromChild"].Value = ErrorMessageToPassToParent;
      
              vars.Unlock();
          }
      
    3. 在父包中创建字符串变量:OnError_ErrorDescription_FromChild

    4. 在父包中为整个包创建一个 OnError 事件处理程序并向其添加脚本任务。 (就像你对上面的子包所做的那样)

    5. 在脚本任务中以只读方式传递变量:User::OnError_ErrorDescription_FromChild

    6. 在脚本任务中执行以下操作:

          // 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
      

    【讨论】:

    • 我的编码方式与您建议的方式相同。子包失败时不会触发错误事件。
    • 我再次检查了我的代码/流程并与我的笔记进行了比较,它正在工作。愚蠢的问题,但您确定子包失败了吗?您是否关闭了失败时的失败包?没有完整的细节/代码很难提供帮助。
    • 我认为我的设计有问题。我会再看一遍
    【解决方案2】:

    一种方法是让子包使用错误消息填充变量,然后在父包的 OnError(或 OnPostExecute)处理程序中读取该变量。

    【讨论】:

    • 我知道如何将一个变量从孩子共享给父母(我正在使用脚本任务来做)。您是否有更多详细信息和/或如何使用错误详细信息执行此操作的示例?
    • 查看此问题的答案以获取示例链接:stackoverflow.com/questions/9154672/…
    • 我知道包中每个任务/组件的 OnError,我希望为整个包提供更多的全局处理程序。因此,当子包的任何部分发生任何错误以设置变量时,父包可以读取该变量。还是在我不熟悉的包级别存在 OnError?
    • 是的,在包级别有一个 OnError 事件处理程序。选择您的包并打开事件处理程序选项卡。
    猜你喜欢
    • 1970-01-01
    • 2014-06-18
    • 1970-01-01
    • 2020-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多