Poblem: Suppose I have a lookup component inside Data flow task and any mismatch should be treated as error and an appropriate error message should be sent using Send Mail Task.
Solution: Take a data flow task and configure it using an OLEDB source, lookup component and take the error op of lookup to a script component. Check here for error handling using script component. The data flow task would be like:

Create a string variable (in this case the name of variable is Error) and use this variable as ReadWriteVariables inside script component editor as shown below:

Use following code inside the script transformation editor (I am using VB.Net code):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System | |
Imports System.Data | |
Imports System.Math | |
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper | |
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper | |
_ | |
_ | |
Public Class ScriptMain | |
Inherits UserComponent | |
Dim Component As String | |
Public Overrides Sub PreExecute() | |
MyBase.PreExecute() | |
' | |
' Add your code here for preprocessing or remove if not needed | |
' | |
End Sub | |
Public Overrides Sub PostExecute() | |
MyBase.PostExecute() | |
Me.Variables.Error = "Lookup Component Failed" | |
Me.ComponentMetaData.FireError(0, "X", "X", "X", 0, 0) | |
End Sub | |
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer) | |
'Component = ComponentMetaData.Name.Trim() | |
End Sub | |
End Class |
Now create an event handler for the data flow task for "On Task Failed" event and add a Send Mail Task. For demo purpose I am using a script task (as I don't have smtp server configured) as shown below:

Value of variable (Error) can be verified by adding following piece of code inside scipt task editor (don't forget to set Error variable as ReadOnlyVariable inside Scrpt task editor):
Public Sub Main()
System.Windows.Forms.MessageBox.Show(Dts.Variables("Error").Value.ToString())
Dts.TaskResult = ScriptResults.Success
End Sub
i enjoy most of your articles,the articles are so nice for readers.
ReplyDeletecathy
www.gofastek.com