Bir veri akışı bileşeni hata çıkışları kullanarak
Özel IDTSOutput100 nesneleri olarak adlandırılan hata çıkışlarına seçeyim yürütme sırasında işleyemiyor satırları yeniden yönlendirme bileşenini Bileşenler eklenebilirBir bileşen karşılaşabileceğiniz sorunlara genellikle hataları veya truncations olarak kategorize edilir ve her bileşen için özeldir.Hata çıkışlarına sağlayan bileşenleri kullanıcıların bileşen hata satırları süzme yoluyla hata durumları işlemek için esneklik vermek sonuç küme, bir sorun oluştuğunda bileşen başarısız olan veya hataları yoksaymak ve devam eden.
Uygulamak ve hata çıkışlarına bir bileşen, destek için gerekir küme UsesDispositions için bileşenin özellik true.Sonra da bir çıkış olan bileşen ekleme, IsErrorOut özelliği küme için true.Son olarak, bileşen hataları veya truncations oluştuğunda hata çıktı satırları yönlendirir kod içermesi gerekir.Bu konu aşağıdaki üç adımı kapsar ve hata zaman uyumlu ve zaman uyumsuz çıkışlarına arasındaki farklar açıklanmıştır.
Hata çıktı oluşturma
Hata çıktı çağırarak oluşturmak New yöntem, OutputCollectionve ardından ayarlar IsErrorOut özellik için yeni çıktı true.Çıkış zaman uyumsuz ise, başka bir şey için çıkış yapılması gerekir.Zaman uyumlu çıktı ve aynı giriş zaman uyumlu başka bir çıkış vardır, ayrıca gerekir küme ExclusionGroup ve SynchronousInputID özellikleri.Her iki özellikleri için aynı giriş zaman uyumlu çıktı olarak aynı değerleri olmalıdır.Yoksa bu özellikleri küme sıfır olmayan bir değer için giriş zaman uyumlu hem çıkışlarına giriş tarafından sağlanan satır gönderilir.
Bir bileşen, bir hata veya kesilme yürütme sırasında karşılaştığında, ayarlarına göre devam ErrorRowDisposition ve TruncationRowDisposition giriş veya çıkış veya giriş veya çıkış özelliklerini sütun, hatanın oluştuğu.Olması gereken bu özellikleri değerini küme varsayılan olarak RD_NotUsed.Bileşen hata çıktısı için bir aşağı akım bileşeni bağlı olduğunda bu özellik bileşenin kullanıcı tarafından küme ve bileşen bir hata veya kesilme işleme biçimini denetlemenize izin verir.
Hata sütunlar doldurma
Hata çıktı oluşturulur, veri akışı görevi otomatik olarak iki sütun çıkış sütununa ekler koleksiyon.Bu sütunlar bir hata veya kesilme nedeni sütun kimliği belirtin ve bileşen özgü hata kodu sağlamak için bileşenleri tarafından kullanılır.Bu sütunları otomatik olarak oluşturulur, ancak sütunlardaki değerleri olmalıdır küme bileşeni tarafından.
Kullanılan yöntem küme bu sütun değerleri hata çıktı zaman uyumlu veya zaman uyumsuz olmasına bağlıdır.Bileşenleri ile zaman uyumlu çıkışlarına çağrısı DirectErrorRow yöntem, açıklanan sonraki bölümünde daha ayrıntılı ve hata kodu ve hata sütun değerleri olarak parametreleri.Zaman uyumsuz çıkışlarına bileşenlerle bu sütun değerleri ayarlamak için iki seçeneğiniz vardır.Ya da çağrı yapabilir SetErrorInfo Çıkış yöntem arabellek değerlerini sağlamak veya kullanarak hata sütunları arabellekte bulun FindColumnByLineageID ve küme doğrudan sütunlar için değerleri.Ancak, çünkü adları sütuns değişmiş, ya da çıkış konumlarında sütun Koleksiyon değiştirilmiş olabilir, İkinci yöntem güvenilir olabilir.The SetErrorInfo method automatically sets the values in these error columns without having to locate them manually.
Belirli hata koduna karşılık gelen hata açıklaması elde etmeniz gerekirse, kullanabileceğiniz GetErrorDescription yöntem, IDTSComponentMetaData100 arabirim, bileşenin aracılığıyla ComponentMetaData özellik.
Aşağıdaki kod örnekleri bir giriş ve iki çıkış hata çıktı da dahil olmak üzere, bir bileşeni gösterir.İlk örnek, giriş zaman uyumlu hata çıktısının oluşturulması gösterilmiştir.İkinci ö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 hata çıktısının 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 bir hata çıktısını yeniden yönlendirme
Hata çıktı için bir bileşen ekledikten sonra bileşenin belirli hata veya kesilme koşullarını işleme ve hata veya kesilme satır hata çıkışı yönlendirir kodu girmelisiniz.Zaman uyumlu veya zaman uyumsuz hata çıktı olmasına bağlı olarak iki şekilde yapabilirsiniz.
Zaman uyumlu çıkışlarına ile bir satır yeniden yönlendirme
Satır gönderildiği için zaman uyumlu çıkışlarına çağırarak DirectErrorRow yöntem, PipelineBuffer WalkTreeYöntem çağrısında hata çıktı, bileşen tanımlı hata kodu ve dizin kimliği parametreleri içeren sütun bileşen işleyemiyor.
Aşağıdaki kod örneği satır eşzamanlı hata kullanarak çıkış arabellekte doğrudan gösterilmiştir DirectErrorRow 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ına yeniden yönlendirme
İçin bir çıkış satır ile zaman uyumlu hata çıkışlarına yapıldığının suna yerine, zaman uyumsuz çıkışlarına bileşenlerle satır bir hata çıktısı açıkça çıktı bir satır ekleyerek göndermek PipelineBuffer.Zaman uyumsuz hata çıkışlarına kullanan bir bileşeni uygulamak için aşağı akım bileşenleri için sağlanan hata çıktı sütunları ekleme ve hata çıktı arabelleği önbelleğe alma çıkış sırasında bileşen için sağlanan PrimeOutput yöntem.Zaman uyumsuz çıkışlarına bileşeniyle uygulama ayrıntıları konusunda ayrıntılı ele alınacaktır Bir zaman uyumsuz çıkışlarına ile özel dönüşümü Bileşen geliştirme.Hata çıktı sütunları açıkça eklenmezse, yalnızca iki hata sütunları çıkış arabelleği eklenen arabellek satır içerir.
Bir satır bir zaman uyumsuz hata Çıkışı göndermek için hata çıktı arabelleği için satır eklemeniz gerekir.Bazı durumlarda, bir satır zaten olmayan hata çıktı arabelleği için eklenmiş olabilecek ve bu satır kullanarak kaldırmalısınız RemoveRow yöntem.İleri, küme çıkış arabelleği sütun değerleri ve son olarak, çağrı SetErrorInfo yöntem bileşen özgü hata kodu ve hata sütun değeri.
Aşağıdaki örnek, bir bileşeni ile zaman uyumsuz çıkışlarına hata çıktı kullanımı gösterilmiştir.Benzetimli hatası oluştuğunda, bileşeni olmayan hata çıktı arabelleği için eklenen satır arabellek, kopya olmayan hata çıktı daha önce eklenen değerleri hata çıktı arabelleği için arabellek kaldırır bir satır hata çıktı eklerve son olarak çağırarak hata kodu ve hata sütun değerlerini ayarlar SetErrorInfo 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
|
Ayrıca bkz.