This project is read-only.

Event Notifications Sample

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

This sample works only with SQL Server 2005 and SQL Server 2008. It will not work with any version of SQL Server earlier than SQL Server 2005.
The event notification sample (EventNotificationSample.sql) provides an example of how event notifications can be used in an OLTP database application. For more information, see Event Notifications (Database Engine).

Samples are provided for educational purposes only. They are not intended to be used in a production environment and have not been tested in a production environment. Microsoft does not provide technical support for these samples. Sample applications should not be connected to or used with your production SQL Server database without the permission of the system administrator.


Event notifications can be used to monitor and respond to database activity. EventNotificationSample.sql monitors the following kinds of events:
  • CreateDatabaseNotification event notification monitors when databases are created and dropped on the server instance.
  • AuditLoginLogoutNotification event notification monitors when logins, logouts, and failed logins occur on the server instance. The event notifications send XML data about these events to the Microsoft Service Broker service specified in the sample. The sample also defines a queue to receive the messages and a route that specifies the service address; in this case, the address is the local database. A WAITFOR clause, which is enclosed in commenting characters, instructs the server to wait 60 seconds until the service receives the message and casts it as xml. Additional scripts, which are also enclosed in commenting characters, test the event notifications by causing the events on which they are created to occur on the server instance.




Before running this sample, make sure the following software is installed:
  • Microsoft SQL Server with the following components:
  • Database Engine
  • SQL Server Management Studio
  • AdventureWorks (OLTP) sample database which is included with SQL Server, and is also available at the Microsoft SQL Server Developer Center.
  • SQL Server Database Engine samples (SQLServerSample.msi). These samples are included with SQL Server. You can download the latest version of the samples at the Microsoft SQL Server Developer Center.

Running the Sample

The following procedure shows how to install and run the event notification sample.
To run the event notification sample
  1. From SQL Server Management Studio, open EventNotificationSample.sql. The default installation directory is C:\Program Files\Microsoft SQL Server\100\Samples\Engine\Administration\EventNotifications\Scripts\.
  2. Click Execute. © 2007 Microsoft Corporation. All rights reserved.

Last edited Jun 5, 2007 at 6:55 PM by bonniefe, version 5


No comments yet.