Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
子包失败时SSIS将完整错误传递给父包_Ssis_Parent Child - Fatal编程技术网

子包失败时SSIS将完整错误传递给父包

子包失败时SSIS将完整错误传递给父包,ssis,parent-child,Ssis,Parent Child,我有一个调用子包的父包。如果子包失败,将显示子包的完整错误详细信息,但父包只显示“任务执行包失败” 如何让父包从子包获取完整的错误消息,以便正确获取父包中的完整错误详细信息?一种方法是让子包使用错误消息填充变量,然后在父包的OnError(或OnPostExecute)处理程序中读取该变量。解决方案: 如何从子包中获取错误详细信息 此解决方案将接受子包出现的任何错误,并将错误消息传递给父包。然后父包将接受它接收到的错误,并在父包执行结果中发布完整的详细信息 注意:编写逻辑时,子包仍然可以自己运行

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


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

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

解决方案:

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

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

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

  • 为整个子包创建了OnError事件处理程序

  • 将脚本任务添加到事件处理程序

    a。以只读方式传递变量:System::ErrorDescription、System::SourceName、System::PackageName

    b。在脚本任务中执行此操作(注释应详细说明它正在执行的操作):

  • 在父包中创建一个字符串变量:OnError\u ErrorDescription\u FromChild

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

  • 在脚本任务中,以只读形式传递变量:User::OnError\u ErrorDescription\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
    

  • 我知道如何将一个变量从子变量共享到父变量(我是通过脚本任务来实现的)。您是否有关于如何处理错误详细信息的更多详细信息和/或示例?有关示例的链接,请参阅此问题的答案:我知道包中每个任务/组件的错误,我希望整个包有更多全局处理程序。因此,当在子包的任何部分发生设置变量的错误时,父包可以读取该变量。或者在包级别是否存在我不熟悉的OneError?是的,在包级别存在OneError事件处理程序。选择您的包并打开事件处理程序选项卡。我已经按照您建议的方式编写了代码。子包失败时不会触发On error事件。我再次检查了代码/流程,并将其与notes进行了比较,结果表明它正常工作。愚蠢的问题,但你确定子包失败了?您是否关闭了故障时的故障包?没有完整的细节/代码很难帮助。我认为我的设计有缺陷。我会再看一遍
        // 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