Saturday, May 19, 2012

Setup SQL Server 2008 Maintenance Plan Email Notifications

To take backup most of the SQL installs that I maintain, SQL dumps to disk and then copy to tape. I use a simple maintenance plan that dumps all user databases to the local disk and then a cleanup task that purges backup files older than a set number of days. An email alert with either success or fail in the subject line is sent out after each maintenance plan task is completed. Here we will review step by step how to add email notifications to your existing SQL 2008 maintenance plan.


Setting up an alert to e-mail an operator with a message is a multiple step process. You can setup database mail, define an operator and an alert. So how do you send an alert to an operator?
Step: 1
Database Mail: First setup database mail with a profile named "TestDb/SQLAlerts". The profile can be named anything but in these instructions, the profile name SQLAlerts is referenced. If you wish to use a different profile name just substitute accordingly. For procedures in setting up database mail, see this Post First
Step: 2
Define Operator : Connect to the instance using Microsoft SQL Management Studio
Double Click SQL Server Agent-->Right Click on Operators and select New Operator
Specify an operator Name, E-mail name
Select Ok button. New operator will be create.
Step: 3
Setup SQL Agent Settings
Note: This step is often overlooked when creating an alert for the first time. SQL Agent must be setup correctly for operators to receive an alert e-mail.
Right Click SQL Server Agent > select Properties
Popup window will display select Alert System in the left pane then follow below steps.
Checkmark > Enable mail profile
Verify Mail system: Database Mail
Verify Mail Profile: TestDB
Checkmark > Include body of e-mail in the notification message
Click OK.
Restart SQL Agent to activate settings.
Warning: Restarting SQL Agent will cancel any executing jobs.
Next, right click on designated maintenance plan (assuming one is already configured) and select Modify
This should bring up the design window with the current tasks
From the Toolbox window Drag and drop Notify Operator Task to Design window twice. One for success and the other for fail. Notify Operator Task, it shows cross mark.  
We need to configure to that to do that Double click each Notify Operator Task > check which operators to notify if there are more than one > fill out Subject and Body fields > select OK
Design window with the current tasks will look like this.
Connect the backup database task to each Notify Operator Task and make sure the arrows are pointing down.  Designate one of the Notify Operator Task objects connection arrows as Failure. Right click on connection and select Failure. This will turn the connection arrow red.
Save maintenance plan and test it.
One of the nice features of the Notify Operator Task in SQL 2008 that wasn't an option in SQL 2005 is the ability to add a unique subject line to the message. Its helpful to be able to see the success or fail status at a glance from just the subject line. 

4 comments:

  1. You can indeed set up a notification on your task through a maintenance plan, but you can only access/review the job/plan if you're connected to it. Which from my point of view, in this day and age isn't a bonus anymore.

    Using the WEB to get access to any information you might need is the way it should be. In this sense, an alternative that I propose is to use web based tools because they are generally simpler and faster to get the job done.

    I've actually taken a thorough search over the Internet and found a really great tool, which in the end I've continued to use with my backups. It's called SqlBak and here's how easy it is with using this tool to actually get notified on the status of your jobs.

    ReplyDelete
  2. Great concepts on this blog. This is really a nice post.I really like the way you start and add your thoughts. Thank you very much for this information.Server Maintenance

    ReplyDelete
  3. I would never have find all that stuff in Management Studio.
    Thank you very much, yjeevanrao.

    ReplyDelete
  4. Unable to Setup MS SQL Server Alerts? Contact to Microsoft SQL Server Support
    Guarantee, setting up an alert requires a different propel process yet in the occasion that still you are not prepared to setup the prepared by then connect with Remote Infrastructure Management Support for Microsoft SQL Server or Online MS SQL Server Support. At Cognegic we place stock in start to finish course of action and help for your MS SQL Server. We effectively track the execution of your server and alert you if any issue has happened. We take out your botches by ensuring that issues are easily and immediately separated. Contact to our SQL Server Database Support.
    For More Info: https://cognegicsystems.com/
    Contact Number: 1-800-450-8670
    Email Address- info@cognegicsystems.com
    Company’s Address- 507 Copper Square Drive Bethel Connecticut (USA) 06801

    ReplyDelete