Compartilhar via


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

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

Other Resources

Using the .NET Framework Data Provider for SQL Server