Bir veri akışı bileşeni'nde hata çıkışlarını kullanma

Özel IDTSOutput100 Hata çıkışlarını adlı nesneleri bileşenler, bileşen, yürütme sırasında işleyemiyor satırları yeniden yönlendirmek için eklenebilir. Bir bileşen olarak karşılaşabileceğiniz sorunlar genellikle hataları veya truncations olarak kategorize edilir ve her bileşen için özeldir.Hata çıkışlarını sağlayan bileşenleri, kullanıcıların bileşen hata satırlarını sonuç süzerek hata koşullarını işlemek için esneklik sağlar küme, bir sorun ortaya çıktığında, bileşen başarısız olarak veya hataları yok sayarak ve devam etmeden.

Uygulama ve bir bileşen hata çıkışlarını desteklemek için gerekir küme UsesDispositions() bileşenin özellik true. Bileşene sahip bir çıkış ekleyin sonra IsErrorOut() özellik küme için true. Son olarak, bileşen hataları veya truncations satır hata çıkışı yeniden yönlendirir kodunu içermesi gerekir.Bu konu, aşağıdaki üç adımı kapsar ve zaman uyumlu ve zaman uyumsuz hata çıkışlarını arasındaki farklar açıklanır.

Bir hata çıktı oluşturma

Bir hata çıktı çaðýrarak oluşturma New() yöntem OutputCollection()ve sonra IsErrorOut() Yeni çıktısına özellik true. Çıkış zaman uyumsuz ise, başka bir şey için çıkış yapılması gerekir.Çıkış zaman uyumlu olarak çalışır ve aynı giriş için zaman uyumlu olan başka bir çıkış yok, ayrıca gerekir küme ExclusionGroup() ve SynchronousInputID() özellikleri. Her iki özelliği de aynı giriş için zaman uyumlu olan diğer çıktı olarak aynı değerlere sahip olması gerekir.Bu özellikler değilseniz küme bir sıfır olmayan değer giriş için zaman uyumlu olan iki çıktılarının giriş sağlanan satır gönderilir.

Bir bileşen, bir hata ya da yürütme sırasında kesme karşılaştığında, ayarlarına göre gerçekleştirilir ErrorRowDisposition() ve TruncationRowDisposition() Giriş veya çıkış veya giriş veya çıkış sütun, hatanın oluştuğu özellikleri. Bu özelliklerin değeri küme varsayılan olarak RD_NotUsed(). Bileşen hata çıktısını akış yönündeki bir bileşene bağlandığınızda, bu özellik, bileşenin kullanıcı tarafından küme ve bileşen, hata veya kesme nasıl işleyeceğini denetleyen izin verir.

Hata sütunlar doldurma

Bir hata çıktı oluşturulduğunda, veri akışı görevi iki sütun otomatik olarak çıkış sütunu derlemesine ekler.Bu sütun, hata veya kesilmesi nedeniyle sütunun KIMLIĞINI belirtmek iççin ve bileşen özel hata kodu sağlamak için bileşenleri tarafından kullanılır.Bu sütunları otomatik olarak oluşturulur, ancak bu sütunlarda bulunan değerleri bileşeni tarafından küme olması gerekir.

Için kullanılan yöntem küme bu sütunların değerleri bağlıdır hata çıktı zaman uyumlu veya zaman uyumsuz olmasına göre.Zaman uyumlu çıkışlarını çağrısıyla bileşenleri DirectErrorRow(Int32, Int32, Int32) yöntem, ayrıntılı başlıklı sonraki bölümde açıklanan ve parametre hata sütun değerlerini ve hata kodu sağlar. Zaman uyumsuz çıkışlarını bileşenlerle bu sütunların değerleri ayarlamak için iki seçeneğiniz vardır.Bunlar ya da arama yapabilirsiniz SetErrorInfo(Int32, Int32, Int32) çıktı yöntem arabellek değerleri girmeniz veya hata sütunları kullanarak arabellekte bulun. FindColumnByLineageID(Int32, Int32) ve küme doğrudan sütunlar için değer. Ancak, sütun adları değiştirilmiş olabilir veya çıktı sütunu koleksiyon konumlarında değişiklik nedeniyle, ikinci yöntem güvenilir olmayabilir.The SetErrorInfo(Int32, Int32, Int32) yöntem automatically sets the values in these error columns without having to locate them manually.

Bir özel hata koduna karşılık gelen hata açıklama edinmek istiyorsanız, kullanabileceğiniz GetErrorDescription(Int32) yöntem IDTSComponentMetaData100 arabirim, bileşenin kullanılabilir ComponentMetaData() özellik.

Aşağıdaki kod örnekleri, giriş ve bir hata çıktı dahil olmak üzere iki çıkış, bir bileşeni gösterir.Ilk örnek, giriş için zaman uyumlu olan bir hata çıktı oluşturulması gösterilmiştir.Ikinci örnek, zaman uyumsuz hata çıktısının oluşturulması gösterilmiştir.

public override void ProvideComponentProperties()
{
    // Specify that the component has an error output.
    ComponentMetaData.UsesDispositions = true;
    // Create the input.
    IDTSInput100 input = ComponentMetaData.InputCollection.New();
    input.Name = "Input";
    input.ErrorRowDisposition = DTSRowDisposition.RD_NotUsed;
    input.ErrorOrTruncationOperation = "A string describing the possible error or truncation that may occur during execution.";

    // Create the default output.
    IDTSOutput100 output = ComponentMetaData.OutputCollection.New();
    output.Name = "Output";
    output.SynchronousInputID = input.ID;
    output.ExclusionGroup = 1;

    // Create the error output.
    IDTSOutput100 errorOutput = ComponentMetaData.OutputCollection.New();
    errorOutput.IsErrorOut = true;
    errorOutput.Name = "ErrorOutput";
    errorOutput.SynchronousInputID = input.ID;
    errorOutput.ExclusionGroup = 1;

}
Public  Overrides Sub ProvideComponentProperties() 

 ' Specify that the component has an error output.
 ComponentMetaData.UsesDispositions = True 

 Dim input As IDTSInput100 = ComponentMetaData.InputCollection.New 

 ' Create the input.
 input.Name = "Input" 
 input.ErrorRowDisposition = DTSRowDisposition.RD_NotUsed 
 input.ErrorOrTruncationOperation = "A string describing the possible error or truncation that may occur during execution." 

 ' Create the default output.
 Dim output As IDTSOutput100 = ComponentMetaData.OutputCollection.New 
 output.Name = "Output" 
 output.SynchronousInputID = input.ID 
 output.ExclusionGroup = 1 

 ' Create the error output.
 Dim errorOutput As IDTSOutput100 = ComponentMetaData.OutputCollection.New 
 errorOutput.IsErrorOut = True 
 errorOutput.Name = "ErrorOutput" 
 errorOutput.SynchronousInputID = input.ID 
 errorOutput.ExclusionGroup = 1 

End Sub

Aşağıdaki kod örneği, zaman uyumsuz olan bir hata çıktı oluşturur.

public override void ProvideComponentProperties()
{
    // Specify that the component has an error output.
    ComponentMetaData.UsesDispositions = true;

    // Create the input.
    IDTSInput100 input = ComponentMetaData.InputCollection.New();
    input.Name = "Input";
    input.ErrorRowDisposition = DTSRowDisposition.RD_NotUsed;
    input.ErrorOrTruncationOperation = "A string describing the possible error or truncation that may occur during execution.";

    // Create the default output.
    IDTSOutput100 output = ComponentMetaData.OutputCollection.New();
    output.Name = "Output";

    // Create the error output.
    IDTSOutput100 errorOutput = ComponentMetaData.OutputCollection.New();
    errorOutput.Name = "ErrorOutput";
    errorOutput.IsErrorOut = true;
}
Public  Overrides Sub ProvideComponentProperties() 

 ' Specify that the component has an error output.
 ComponentMetaData.UsesDispositions = True 

 ' Create the input.
 Dim input As IDTSInput100 = ComponentMetaData.InputCollection.New 

 ' Create the default output.
 input.Name = "Input" 
 input.ErrorRowDisposition = DTSRowDisposition.RD_NotUsed 
 input.ErrorOrTruncationOperation = "A string describing the possible error or truncation that may occur during execution." 

 ' Create the error output.
 Dim output As IDTSOutput100 = ComponentMetaData.OutputCollection.New 
 output.Name = "Output" 
 Dim errorOutput As IDTSOutput100 = ComponentMetaData.OutputCollection.New 
 errorOutput.Name = "ErrorOutput" 
 errorOutput.IsErrorOut = True 

End Sub

Bir satır için bir hata çıktı yeniden yönlendirme

Bir hata çıktı için bir bileşen eklendikten sonra bileşene özgü kesilmesi ya da hata koşullarını işleme ve hata veya kesme satırları hata çıkışı yeniden yönlendirir kodu girmelisiniz.Zaman uyumlu veya zaman uyumsuz hata çıktı olmasına bağlı olarak, iki şekilde yapabilirsiniz.

Bir satır ile zaman uyumlu çıkışlarını yeniden yönlendirme

Satır için zaman uyumlu çıkışlarını çaðýrarak gönderilen DirectErrorRow(Int32, Int32, Int32) yöntem PipelineBuffer sınıf. Yöntem çağrısında parametre olarak hata çıktı, bileşen tanımlı hata kodu ve bileşen işleyemedi sütunun dizin KIMLIĞINI içerir.

Aşağıdaki kod örneği, bir arabellek kullanarak çıktı zaman uyumlu bir hata için bir satır yönlendirileceği gösterilmiştir DirectErrorRow(Int32, Int32, Int32) yöntem.

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

        // This code sample assumes the component has two 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 before they occur, rather
                // than having a generic try/catch block such as this. 
                // However, because 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 errorColumnIndex.
                    buffer.DirectErrorRow(errorOutputID, 0, errorColumnIndex);
                }
                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) 

   ' This code sample assumes the component has two 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.
   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 
       ' TODO: Implement code to process the columns in the buffer row.

       ' Ideally, your code should detect potential exceptions before they occur, rather
       ' than having a generic try/catch block such as this. 
       ' However, because 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 Then 
         ' Yes, direct the row to the error output.
         ' TODO: Add code to include the errorColumnIndex.
         buffer.DirectErrorRow(errorOutputID, 0, errorColumnIndex) 
       Else 
         If input.ErrorRowDisposition = DTSRowDisposition.RD_FailComponent OrElse input.ErrorRowDisposition = DTSRowDisposition.RD_NotUsed Then 
           ' 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) 
         End If 
       End If 
     End Try 
   End While 
End Sub

Bir satır ile zaman uyumsuz çıkışlarını yeniden yönlendirme

Satır için bir çıkış suna yerine ile zaman uyumlu hata çıkışlarını, Bitti olarak zaman uyumsuz çıkışlarını bileşenlerle bir satır için bir hata çıktı açıkça çıktısına bir satır ekleyerek göndermek PipelineBuffer. Zaman uyumsuz hata çıkışlarını kullanan bir bileşenin uygulama akış yönündeki bileşenlere sağlanan hata çıktı sütunları ekleme gerektirir ve bileşen sırasında sağlanan çıkış arabelleği hata için önbelleğe alma çıkış PrimeOutput(Int32, array<Int32[], array<PipelineBuffer[]) yöntem. Bir zaman uyumsuz çıkışlarını bileşeniyle uygulama ayrıntılarını konusunda ayrıntılı kapsanır Zaman uyumsuz çıkışlarını ile özel bir dönüştürme bileşen geliştirme. Sütunlar için hata çıktı açıkça eklenmez, çıkış arabelleği için eklenen arabellek satırı, yalnızca iki hata sütunları içerir.

Bir satır için bir zaman uyumsuz hata çıktısı göndermek için , hata çıktı arabelleği için bir satır eklemelisiniz.Bazı durumlarda, bir satır olmayan hata çıktı arabelleği için zaten eklenmiş olabilir ve bu satırın kullanarak kaldırmalısınız RemoveRow() yöntem. Sonraki çıkış arabelleği sütun değerleri ayarlamak ve son olarak, arama SetErrorInfo(Int32, Int32, Int32) bileşen özel hata kodu ve hata sütun değeri sağlamak için yöntem.

Aşağıdaki örnek, bir zaman uyumsuz çıkışlarını bileşeni bir hata çıktı gösterilmiştir.Benzetimli hatası oluştuğunda, bileşen hata için bir satır olmayan hata çıktı arabelleği için eklenen satır olmayan hata çıktı için önceden eklenen değerleri için hata çıktı arabelleği, arabellek kopya arabelleğinde kaldırır çıktı ekler ve son olarak, ayarlar çaðýrarak hata kodunu ve hata sütun değerleri SetErrorInfo(Int32, Int32, Int32) yöntem.

int []columnIndex;
int errorOutputID = -1;
int errorOutputIndex = -1;

public override void PreExecute()
{
    IDTSOutput100 defaultOutput = null;

    this.GetErrorOutputInfo(ref errorOutputID, ref errorOutputIndex);
    foreach (IDTSOutput100 output in ComponentMetaData.OutputCollection)
    {
        if (output.ID != errorOutputID)
            defaultOutput = output;
    }

    columnIndex = new int[defaultOutput.OutputColumnCollection.Count];

    for(int col =0 ; col < defaultOutput.OutputColumnCollection.Count; col++)
    {
        IDTSOutputColumn100 column = defaultOutput.OutputColumnCollection[col];
        columnIndex[col] = BufferManager.FindColumnByLineageID(defaultOutput.Buffer, column.LineageID);
    }
}

public override void PrimeOutput(int outputs, int[] outputIDs, PipelineBuffer[] buffers)
{
    for( int x=0; x < outputs; x++ )
    {
        if (outputIDs[x] == errorOutputID)
            this.errorBuffer = buffers[x];
        else
            this.defaultBuffer = buffers[x];
    }

    int rows = 100;

    Random random = new Random(System.DateTime.Now.Millisecond);

    for (int row = 0; row < rows; row++)
    {
        try
        {
            defaultBuffer.AddRow();

            for (int x = 0; x < columnIndex.Length; x++)
                defaultBuffer[columnIndex[x]] = random.Next();

            // Simulate an error.
            if ((row % 2) == 0)
                throw new Exception("A simulated error.");
        }
        catch
        {
            // Add a row to the error buffer.
            errorBuffer.AddRow();

            // Get the values from the default buffer
            // and copy them to the error buffer.
            for (int x = 0; x < columnIndex.Length; x++)
                errorBuffer[columnIndex[x]] = defaultBuffer[columnIndex[x]];

            // Set the error information.
            errorBuffer.SetErrorInfo(errorOutputID, 1, 0);

            // Remove the row that was added to the default buffer.
            defaultBuffer.RemoveRow();
        }
    }

    if (defaultBuffer != null)
        defaultBuffer.SetEndOfRowset();

    if (errorBuffer != null)
        errorBuffer.SetEndOfRowset();
}
Private columnIndex As Integer() 
Private errorOutputID As Integer = -1 
Private errorOutputIndex As Integer = -1 

Public  Overrides Sub PreExecute() 
 Dim defaultOutput As IDTSOutput100 = Nothing 
 Me.GetErrorOutputInfo(errorOutputID, errorOutputIndex) 
 For Each output As IDTSOutput100 In ComponentMetaData.OutputCollection 
   If Not (output.ID = errorOutputID) Then 
     defaultOutput = output 
   End If 
 Next 
 columnIndex = New Integer(defaultOutput.OutputColumnCollection.Count) {} 
 Dim col As Integer = 0 
 While col < defaultOutput.OutputColumnCollection.Count 
   Dim column As IDTSOutputColumn100 = defaultOutput.OutputColumnCollection(col) 
   columnIndex(col) = BufferManager.FindColumnByLineageID(defaultOutput.Buffer, column.LineageID) 
   System.Math.Min(System.Threading.Interlocked.Increment(col),col-1) 
 End While 
End Sub 

Public  Overrides Sub PrimeOutput(ByVal outputs As Integer, ByVal outputIDs As Integer(), ByVal buffers As PipelineBuffer()) 
 Dim x As Integer = 0 
 While x < outputs 
   If outputIDs(x) = errorOutputID Then 
     Me.errorBuffer = buffers(x) 
   Else 
     Me.defaultBuffer = buffers(x) 
   End If 
   System.Math.Min(System.Threading.Interlocked.Increment(x),x-1) 
 End While 
 Dim rows As Integer = 100 
 Dim random As Random = New Random(System.DateTime.Now.Millisecond) 
 Dim row As Integer = 0 
 While row < rows 
   Try 
     defaultBuffer.AddRow 
     Dim x As Integer = 0 
     While x < columnIndex.Length 
       defaultBuffer(columnIndex(x)) = random.Next 
       System.Math.Min(System.Threading.Interlocked.Increment(x),x-1) 
     End While 
     ' Simulate an error.
     If (row Mod 2) = 0 Then 
       Throw New Exception("A simulated error.") 
     End If 
   Catch 
     ' Add a row to the error buffer.
     errorBuffer.AddRow 
     ' Get the values from the default buffer
     ' and copy them to the error buffer.
     Dim x As Integer = 0 
     While x < columnIndex.Length 
       errorBuffer(columnIndex(x)) = defaultBuffer(columnIndex(x)) 
       System.Math.Min(System.Threading.Interlocked.Increment(x),x-1) 
     End While 
     ' Set the error information.
     errorBuffer.SetErrorInfo(errorOutputID, 1, 0) 
     ' Remove the row that was added to the default buffer.
     defaultBuffer.RemoveRow 
   End Try 
   System.Math.Min(System.Threading.Interlocked.Increment(row),row-1) 
 End While 
 If Not (defaultBuffer Is Nothing) Then 
   defaultBuffer.SetEndOfRowset 
 End If 
 If Not (errorBuffer Is Nothing) Then 
   errorBuffer.SetEndOfRowset 
 End If 
End Sub
Integration Services icon (small) Tümleştirme Hizmetleri ile güncel kalın

Karşıdan yüklemeler, makaleleri, örnekler ve en son Microsoft video yanı sıra, seçili topluluğun çözümleri için ziyaret Integration Services sayfa MSDN veya TechNet:

Bu güncelleştirmelerin otomatik bildirim için kullanılabilir RSS akışlarına abone olmak sayfa.