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:
-
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.
-
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.
-
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
Reference
See Also