The System.Data.SqlClient.SqlDependency object represents a query notification dependency between an application and an instance of SQL Server. An application can create a System.Data.SqlClient.SqlDependency object and register to receive notifications via the System.Data.SqlClient.OnChangeEventHandler event handler.
See Also: SqlDependency Members
System.Data.SqlClient.SqlDependency is ideal for caching scenarios, where your ASP.NET application or middle-tier service needs to keep certain information cached in memory. System.Data.SqlClient.SqlDependency allows you to receive notifications when the original data in the database changes so that the cache can be refreshed.
To set up a dependency, you need to associate a System.Data.SqlClient.SqlDependency object to one or more System.Data.SqlClient.SqlCommand objects. To receive notifications, you need to subscribe to the SqlDependency.OnChange event. For more information about the requirements for creating queries for notifications, see "Creating a Query for Notification" in SQL Server Books Online.
System.Data.SqlClient.SqlDependency was designed to be used in ASP.NET or middle-tier services where there is a relatively small number of servers having dependencies active against the database. It was not designed for use in client applications, where hundreds or thousands of client computers would have System.Data.SqlClient.SqlDependency objects set up for a single database server. If you are developing an application where you need reliable sub-second notifications when data changes, review the sections Planning an Efficient Query Notifications Strategy and Alternatives to Query Notifications in the tp://go.microsoft.com/fwlink/?LinkId=211984 topic in SQL Server Books Online.
For more information, see Using Query Notifications and "Building Notification Solutions" in SQL Server Books Online.
The SqlDependency.OnChange event may be generated on a different thread from the thread that initiated command execution.
Query notifications are supported only for SELECT statements that meet a list of specific requirements. The following table provides links to the Service Broker and Query Notifications documentation in SQL Server Books Online.
SQL Server Books Online