2016-09-15 7 views
0

子パッケージを呼び出す親パッケージがあります。子パッケージが失敗すると、子パッケージの完全なエラーの詳細が表示されますが、親パッケージは「タスク実行パッケージが失敗しました」と表示されます。子パッケージが失敗するとSSISが親パッケージにFULLエラーを渡す

親パッケージで完全なエラーの詳細を正しく取得できるように、親パッケージが子パッケージから完全なエラーメッセージを取得するにはどうすればよいですか?

答えて

0

1つの方法は、子パッケージにエラーメッセージを変数に取り込み、その変数を親のOnError(またはOnPostExecute)ハンドラで読み取ることです。

+0

私は子供から親に変数を共有する方法を知っています(私はスクリプトタスクでそれをやっています)。 エラーの詳細についてこれ以上の詳細や方法の例がありますか? – Brad

+0

例へのリンクについては、この質問に対する回答を参照してください。http://stackoverflow.com/questions/9154672/which-ssis-system-variable-holds-error-text –

+0

こちらもご覧ください:http://www.sqlservercentral .com/Forums/Topic451275-148-1.aspx –

0

解決策:

子パッケージからエラーの詳細を取得する方法。

このソリューションは、子パッケージが持つすべてのエラーを受け取り、エラーメッセージを親パッケージまで渡します。その後、親パッケージは受信したエラーを受け取り、親パッケージの実行結果に詳細を投稿します。

注:ロジックは、親パッケージの変数名に誤りがない場合でも、子パッケージはそれ自体で(子パッケージではなく)実行できます。さらに、親パッケージから子パッケージを実行しても、子パッケージからエラーをキャプチャしたくない場合は、変数名またはOnErrorイベントハンドラを含めないでください。このように変数が欠落してもエラーは発生しません。

  1. 子パッケージ全体のOnErrorイベントハンドラを作成しました。

  2. イベントハンドラにスクリプトタスクを追加します。

    a。読み取り専用で変数に渡します:System :: ErrorDescription、System :: SourceName、System :: PackageName

    b。スクリプトタスクでは、この(コメントは、それが何をしているかを詳細にすべきである)ん:親パッケージで

    // 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. 文字列変数を作成します。親パッケージで

  4. がためのonErrorイベントハンドラを作成OnError_ErrorDescription_FromChildパッケージ全体を作成し、スクリプトタスクを追加します。読み取り専用として変数を渡すスクリプトタスクで

  5. (同様に上記の子パッケージで行った):ユーザー::スクリプトタスクでは

  6. をOnError_ErrorDescription_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 
    
関連する問題