Using Query Notifications 

Query notifications are a new feature available in Microsoft SQL Server 2005 and the System.Data.SqlClient namespace in ADO.NET 2.0. Built upon the Service Broker infrastructure introduced in SQL Server 2005, query notifications allow applications to be notified when data has changed. This feature is particularly useful for applications that provide a cache of information from a database, such as a Web application, and need to be notified when the source data is changed.

There are three ways you can implement query notifications using ADO.NET:

  1. The low-level implementation is provided by the SqlNotificationRequest class that exposes server-side functionality, enabling you to execute a command with a notification request.

  2. The high-level implementation is provided by the SqlDependency class which is a class that provides a high-level abstraction of notification functionality between the source application and SQL Server, enabling you to use a dependency to detect changes in the server. In most cases, this the simplest and most effective way to leverage SQL Server 2005 notifications capability by managed client applications using the .NET Framework Data Provider for SQL Server.

  3. In addition, Web applications built using ASP.NET 2.0 can use the SqlCacheDependency helper classes.

Query notifications are useful for applications that need to refresh displays or caches (for example, in a DataGrid control or Web page) in response to changes in underlying data. Microsoft SQL Server 2005 allows .NET Framework applications to send a command to SQL Server and request that a notification be generated if executing the same command would produce result sets different from those initially retrieved.

The notifications infrastructure is built on top of a new queuing feature included in SQL Server 2005. In general, notifications generated at the server are sent through these queues to be processed later. For more information, see "Queues" in SQL Server Books Online.

In This Section

Enabling Query Notifications

Discusses how to use query notifications including the requirements for using it and how to enable it.

Using SqlNotificationRequest and Detecting Notifications

Demonstrates how to use query notifications from a Windows forms application.

Using SqlDependency in a Windows Application

Provides examples of query notifications in Windows Forms applications and ASP.NET applications.

Using SqlDependency in an ASP.NET Application

Demonstrates how to use query notifications from an ASP.NET application.

Special Considerations When Using Query Notifications

Discusses import issues to be aware of when using query notifications.

Using a Dependency to Detect Changes in the Server

Demonstrates how to detect when query results will be different from those originally received.

Executing a Command with a Notification Request

Demonstrates configuring a SqlCommand object to work with a query notification.



Describes the SqlNotificationRequest class and all of its members.


Describes the SqlDependency class and all of its members.


Describes the SqlCacheDependency class and all of its members.

See Also