Submitted byCategory
Review Cycle
.
Public
Joachim Mutter/sysarc
on 01/29/2007 at 05:45 PM
SSiS\Code

Convert Blob to String

This small task converts the input row of a text reader (flat file) to normal ascii text
and writes it out to a column named "ErrorDescription", which must be defined in the
data flow.

Here is the code

Public Class ScriptMain
Inherits UserComponent

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
'
' Add your code here
'

Dim wholeRowBuffer As Byte()
Dim szText As String

'Conversion compliation error - cannot convert from byte array to 'Microsoft.SqlServer.Dts.Pipeline.BlobColumn'
wholeRowBuffer = Row.FlatFileSourceErrorOutputColumn.GetBlobData(0, CInt(Row.FlatFileSourceErrorOutputColumn.Length))
szText = Join(Split(System.Text.Encoding.UTF8.GetString(wholeRowBuffer), Chr(9)), "][")

Dim ErrorDescription As String
Dim tmp As String

If Not IsDBNull(Row.ErrorColumn) Then ' Is there a Column-ID (internal SSIS ID)
If Row.ErrorColumn > 0 Then
ErrorDescription = " (SSIS Column-ID " + CStr(Row.ErrorColumn) + ")" ' Append to the Description string
End If
End If

If (Row.ErrorCode > 0 And Row.ErrorCode < 100) Then ' Ok, if this is an error of our own, write this ID and donit lookup system error (this doesn't exist :-))
ErrorDescription = "Semantic Error " + CStr(Row.ErrorCode)
Else
tmp = Me.ComponentMetaData.GetErrorDescription(Row.ErrorCode) ' Get the corresponmding String for the error number
If InStr(tmp, Chr(13)) > 0 Then tmp = Left(tmp, InStr(tmp, Chr(13)) - 1) ' remove Carriage Return
If InStr(tmp, Chr(10)) > 0 Then tmp = Left(tmp, InStr(tmp, Chr(10)) - 1) ' remove Linefeed
ErrorDescription = ErrorDescription + " : " + tmp
End If

MsgBox(szText, , ErrorDescription)

End Sub

End Class