Skip to main content

Custom email notification using Send Mail Task in SSIS

Let’s say your manager wants you to send summary information of the package (not just a one line message) that you’re running or even if there’s an error occurred during the package run. What will you do? I’m sure BI Express is a good option for this task, also you can create your custom message string and send it through send mail task and execute sql task by passing variable value.


I want to see summary of the package run in email msg, please include following information:

1) Package Start Time
2) Package Completed with Success/Failure
3) Look up Match Records
4) Look up Not Match Records
5) Package End Time

You can use the execute sql task in your package and create custom string using the sql code. After this step store the result set value as a single row and use the variable (SendMail)

 
SELECT 'SSIS Started: ' + CAST(? AS VARCHAR(50))
 + char(10) + char(13)
 + 'Package Completed Succssfully'
 + char(10) + char(13)
 + 'Lookup Match Records: ' + CAST(? AS VARCHAR(10)) 
 + char(10) + char(13)
 + 'Lookup NotMatch Records: ' + CAST(? AS VARCHAR(10))
 + char(10) + char(13)
 + 'SSIS Completed: ' + CONVERT(varchar(20), getdate(), 120)
Make sure, you use the correct parameter mapping for the (?) you use in your sql code(Step by step).

Once you're successfully created execute sql task then right click and run it to make sure, you're not getting errors. At this stage, you already got your custom message string created and store in a variable(Send Mail) value.

Next step, Use Send Mail task and pass that variable value as a message source here:
 You've successfully created your custom message using execute sql task and send it through Send Mail task to the email address you want.

You can also create the same logic for the error handling (when you want to send an error message notification with detail error message using event handler)

Create an on error event handler and use the execute sql task and send mail task there.
Write a sql code and store the result set as a single row (Error) variable
SELECT 'Package Name: ' + ?
 + char(10) + char(13)
 + 'Error Code: ' + ?
 + char(10) + char(13)
 + 'Error: ' + ?

Make sure you use the correct parameter mapping in the execute sql task. (You can add more information here as well as in sql code if you want). This is just an example. After this step simple use the send mail task and pass the variable(Error) value as a message source.
Hope, this information will be helpful to you.
Thanks for vising my blog.

Comments

Popular posts from this blog

_x003C_none_x003E_ FlatFile Error in SSIS

If you are receiving this error in your output file, It is because of the value in the text qualifier property (Text Qualifier = <none>).  When you export the data in a file, you might see the _x003C_none_x003E_ (x003C = "<" and none and x003E = ">") with your original field value. • Do not open the connection manager editor once you finalize everything and just clear out the <none> value  from the property window on the right side (Do not open show editor) and save it. You’re done. • Other way around, You can also define the Expression value for the text qualifier and provide (“”) as a value in the expression. Go to the property --> Expression --> Select the Text qualifier from the drop down list --> provide the expression value (“”)

Keep Column Headers Visible while scrolling in SSRS 2008

When you try to set up Tablix property for keep header visible while scrolling, you will see that it is not working in SSRS 2008 or SSRS 2008 R2. You need to take some extra steps to set up this property 1)       Uncheck keep header visible while scrolling tab under tablix property                            2)       Go to Grouping and Click on the right side arrow (Advanced Mode) 3)       Select the first Static Property in Row Groups (In your report first row should display column headers) 4)       Make Fixed Data = True                  5)       Run the report and you will get column headers visible while scrolling Hope it helps! Thanks

Lookup in SSRS 2008 R2

We use more than one dataset in many of the reports and we always think to join or merge datasets to provide a good solution in reports but we were not able to do it in 2005 or 2008, but now the time has come and microsoft has finally included some cool functions (Lookup, LookupSet, MultiLookup) in SSRS 2008 R2 Let's see how "LOOKUP" works here, Suppose we have a two datasets in the report, ex. one dataset (Store) has store information (StoreID, StoreName, Location, $ Sales etc, Date) and second dataset (Sales) has sales information. (StoreID, Date, Target $ Sales etc.) I will directly grab a columns from first dataset but I also want to display target sales amount as a new column with this information. Now you can use Lookup function here in a new column =LOOKUP(Fields!StoreID.Value,Fields!StoreID.Value,Fields!TargetSales.Value,"Sales") In Lookup function, you need to pass following things:   Value form the first dataset to join with second dataset ...