Export (0) Print
Expand All

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.

Implementing Query Notifications

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 is 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 notification if executing the same command would produce result sets different from those initially retrieved.

Query Notifications Architecture and Service Broker

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 "Service Broker Architecture" section in SQL Server Books Online.

In This Section

Enabling Query Notifications

Discusses how to use query notifications, including the requirements for enabling and using them.

Special Considerations When Using Query Notifications

Discusses issues to be aware of when using query notifications.

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.

Using SqlDependency to Detect Changes in the Server

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

Executing a SqlCommand with a SqlNotificationRequest

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

Reference

SqlNotificationRequest

Describes the SqlNotificationRequest class and all of its members.

SqlDependency

Describes the SqlDependency class and all of its members.

SqlCacheDependency

Describes the SqlCacheDependency class and all of its members.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft