次の方法で共有


DirectErrorRow メソッド (Int32, Int32, Int32)

IsErrorOut プロパティが true である IDTSOutput100 に、PipelineBuffer 行を送信します。

名前空間:  Microsoft.SqlServer.Dts.Pipeline
アセンブリ:  Microsoft.SqlServer.PipelineHost (Microsoft.SqlServer.PipelineHost.dll)

構文

'宣言
Public Sub DirectErrorRow ( _
    outputID As Integer, _
    errorCode As Integer, _
    errorColumn As Integer _
)
'使用
Dim instance As PipelineBuffer
Dim outputID As Integer
Dim errorCode As Integer
Dim errorColumn As Integer

instance.DirectErrorRow(outputID, errorCode, _
    errorColumn)
public void DirectErrorRow(
    int outputID,
    int errorCode,
    int errorColumn
)
public:
void DirectErrorRow(
    int outputID, 
    int errorCode, 
    int errorColumn
)
member DirectErrorRow : 
        outputID:int * 
        errorCode:int * 
        errorColumn:int -> unit 
public function DirectErrorRow(
    outputID : int, 
    errorCode : int, 
    errorColumn : int
)

パラメーター

説明

このメソッドは、IsErrorOut プロパティが true に設定された IDTSOutput100 オブジェクトを持つデータ フロー コンポーネントにより使用されます。これは、コンポーネントがバッファ行の処理中にエラーを検出した場合や、入力、出力、または列に RD_RedirectRow が指定された場合に、コンポーネントにより呼び出されます。

使用例

次のコード例では、DirectErrorRow メソッドを使用し、バッファ内の行を同期エラー出力に送信する方法を示します。

public override void ProcessInput(int inputID, PipelineBuffer buffer)
{
        IDTSInput100 input = ComponentMetaData.InputCollection.GetObjectByID(inputID);

        /// This code sample assumes the component has 2 outputs, one the default,
        /// the other the error output. If the errorOutputIndex returned from GetErrorOutputInfo
        /// is 0, then the default output is the second output in the collection.
        int defaultOutputID = -1;
        int errorOutputID = -1;
        int errorOutputIndex = -1;

        GetErrorOutputInfo(ref errorOutputID,ref errorOutputIndex);

        if (errorOutputIndex == 0)
            defaultOutputID = ComponentMetaData.OutputCollection[1].ID;
        else
            defaultOutputID = ComponentMetaData.OutputCollection[0].ID;

        while (buffer.NextRow())
        {
            try
            {
                /// TODO: Implement code to process the columns in the buffer row.

                /// Ideally, your code should detect potential exceptions prior to them occurring, rather
                /// than having a generic try/catch block such as this. 
                /// However, since the error or truncation implementation is specific to each component
                /// this sample focuses on actually directing the row, and not a single error or truncation.

                /// Unless an exception occurs, direct the row to the default 
                buffer.DirectRow(defaultOutputID);
            }
            catch
            {
                /// Yes. Has the user specified to redirect the row?
                if (input.ErrorRowDisposition == DTSRowDisposition.RD_RedirectRow)
                {
                    /// Yes, direct the row to the error output.
                    /// TODO: Add code to include the errorColumnID
                    buffer.DirectErrorRow(errorOutputID, 0, errorColumnID);
                }
                else if (input.ErrorRowDisposition == DTSRowDisposition.RD_FailComponent || input.ErrorRowDisposition == DTSRowDisposition.RD_NotUsed)
                {
                    /// No, the user specified to fail the component, or the error row disposition was not set.
                    throw new Exception("An error occurred, and the DTSRowDisposition is either not set, or is set to fail component.");
                }
                else
                {
                    /// No, the user specified to ignore the failure so 
                    /// direct the row to the default output.
                    buffer.DirectRow(defaultOutputID);
                }

            }
        }
}
Public  Overrides Sub ProcessInput(ByVal inputID As Integer, ByVal buffer As PipelineBuffer) 
   Dim input As IDTSInput100 = ComponentMetaData.InputCollection.GetObjectByID(inputID) 
   Dim defaultOutputID As Integer = -1 
   Dim errorOutputID As Integer = -1 
   Dim errorOutputIndex As Integer = -1 
   GetErrorOutputInfo(errorOutputID, errorOutputIndex) 
   If errorOutputIndex = 0 Then 
     defaultOutputID = ComponentMetaData.OutputCollection(1).ID 
   Else 
     defaultOutputID = ComponentMetaData.OutputCollection(0).ID 
   End If 
   While buffer.NextRow 
     Try 
       buffer.DirectRow(defaultOutputID) 
     Catch 
       If input.ErrorRowDisposition = DTSRowDisposition.RD_RedirectRow Then 
         buffer.DirectErrorRow(errorOutputID, 0, errorColumnID) 
       Else 
         If input.ErrorRowDisposition = DTSRowDisposition.RD_FailComponent OrElse input.ErrorRowDisposition = DTSRowDisposition.RD_NotUsed Then 
           Throw New Exception("An error occurred, and the DTSRowDisposition is either not set, or is set to fail component.") 
         Else 
           buffer.DirectRow(defaultOutputID) 
         End If 
       End If 
     End Try 
   End While 
End Sub