Using SqlDependency to Subscribe to Query Notifications

Subscribing to a query notification using SqlDependency is straightforward: the SqlDependency object manages the complexity involved in setting up the notification in the database. Once the notification is established, the object monitors the underlying database objects that implement the notification, and calls an event handler in the application when SQL Server creates a query notification.

The ReviewWatcher sample included with SQL Server 2008 demonstrates how to use SqlDependency to subscribe to Query Notifications. Class ReviewWatch creates a query notification subscription using SqlDependency, and updates a form when the query changes. For details on installing and running the ReviewWatcher sample, see Using SqlNotificationRequest to Subscribe to Query Notifications.