VirtualObjectives

SQL Server Restart Notification

If you ever wanted to be notified by email when your SQL Servers are restarted, here is a script which will do just that. It relies on using the "run on Agent Manager startup" option in SQL Jobs.

An alternative method uses sp_procoption

Download SQL Server Restart Notification (Size 2 KiB)

What it does:

This script sets up a scheduled job which will run when the Agent Manager is started. Should tempdb be recently created then this usually indicates that the SQL Server instance has been started. The script then issues an email with the date and time the server was started.

Requirements:

  • SQL Server 2005 and above.
  • You must already have Database Mail setup to support sp_send_dbmail.

Installation:

  1. Run the script.
  2. Go to the newly created job called "SQL Server Restart Notification" under SQL Server Agent + Jobs.
  3. Edit the job and go to Step 1.
  4. Change the line @recipients = 'someone@domainname.com' to be the email address you want to send the alerts to.
  5. Optional: You may also enable the Notifications section so that someone is alerted if this particular job fails for whatever reason.