Quantcast
Channel: Smart ERP Solutions - Microsoft BI
Viewing all articles
Browse latest Browse all 22

Send Error Email with Error Code, Error Description by using Send Mail Task in SSIS Package.

$
0
0

We have created an SSIS Package,  that fails sometime. The only way to find out if the Package is failed to check SQL Server Job history or alerts generated by SQL Server Agent Job. We want to include components in SSIS Package so we can send an Email from SSIS Package with Error Information when the Package fail.

Step 1: 

 I Have Created three variables 

Environment : 

As you will be running your package on different environment, It is good idea to use this variable and change the value according to the environment in which you run the SSIS Package. 

MailProfile : 

Provide the name of mail profile. To get the profile name, you can use this query on SQL Server 

SELECT * FROM msdb.dbo.sysmail_profile

Recipients : 

List all of the recipients you want to send an email, separate them with ";".

e.g: aaaaa@gmail.com;Raju@yahoo.com

Step 2: 

Create OLE DB Connection Manager. I have created connection to SQL Server Database and named it DB_Connection.

Step 3

You will have different Tasks and Transformation in SSIS Package,  I am going to have Execute SQL Task and inside I will be using Select 1/0 to fail this Task so we can test our Error email part.

Step 4: 

Let's go to Event Handler and then Drag Execute SQL Task and configure as shown below

Here is the expression that I have used, You can copy the same and make changes according to your requirements

 

"EXEC msdb.dbo.sp_send_dbmail

 @profile_name = '"+ @[User::Mailprofile] +"',

@recipients = '"+ @[User::Receptience] +"',"

+"

 @body = "+"'Hi ,"+"

Error Information is below

Error Code:  '"+ (DT_STR, 100, 1252) @[System::ErrorCode] +"

Task Name:"+  (DT_STR, 100, 1252) @[System::SourceName] +"

Error Description:" +  (DT_STR, 100, 1252) @[System::ErrorDescription] +

"Thank you

IT Team"+"',

@subject = '"+  (DT_STR, 100, 1252) @[System::PackageName] + " failed in  "+ @[User::Enveronment] +"'"

Step 5:

Execute the SSIS Package, The package will fail as 1/0 is infinity and our Execute SQL Task in Control Flow will throw an error. Once the Task will fail in Control Flow , SSIS Package will jump to Event Handler. In Event Handler we are sending email by using Execute SQL Task on Package Error. We should receive an email as shown below


Viewing all articles
Browse latest Browse all 22

Trending Articles