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:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_MAqT5_uHiKbpELxf12AC5_dB-2Is__c_MfPeyOTZb0D0L55eKQPySR_xpN5qs7G8_38_TxZ_NofDm_Tdabas4JrlzsrLUteFlvAe3EBppGDmOleh3tqgApljLv_2Jv2JcNEvw-NDCN9i/s400/Image1.bmp)
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:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqJtXedFbNwWIugY3aFjN8_034X0VM5JVfBQyBvBtijOSOoaAaAargUZ3YQtgU2rTK-8K3YSXxzT8iw8OyaFXC_OiyRc8S4Qirl9zhfFGYZ7Hesy1o8zdISCW3O4lvzbRhHrC7Sy5HB97j/s400/Image1.bmp)
Use following code inside the script transformation editor (I am using VB.Net code):
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:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcA-L8NoF4J2d1CWu-GGhyphenhyphenhALqiotwh_YV4CefnuwUjtm3_PGHE2yms5G5ncoSI1Y06KGMr2zW12wEkoBMxuwKaE94RhZZOv4RbQMkbmlN7wJRYHTU-hwdf-xy8C42WiljAWmmsVDkbuwR/s400/Image1.bmp)
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