The object represents a query notification dependency between an application and an instance of SQL Server 2005. An application can create a object and register to receive notifications via the OnChangeEventHandler event handler.
Assembly: System.Data (in System.Data.dll)
Thetype exposes the following members.
|SqlDependency()||Creates a new instance of the class with the default settings.|
|SqlDependency(SqlCommand)||Creates a new instance of the class and associates it with the SqlCommand parameter.|
|SqlDependency(SqlCommand, String, Int32)||Creates a new instance of the class, associates it with the SqlCommand parameter, and specifies notification options and a time-out value.|
|AddCommandDependency||Associates a SqlCommand object with this instance.|
|Equals(Object)||Determines whether the specified Object is equal to the current Object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetHashCode||Serves as a hash function for a particular type. (Inherited from Object.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|Start(String)||Starts the listener for receiving dependency change notifications from the instance of SQL Server specified by the connection string.|
|Start(String, String)||Starts the listener for receiving dependency change notifications from the instance of SQL Server specified by the connection string using the specified SQL Server Service Broker queue.|
|Stop(String)||Stops a listener for a connection specified in a previous Start call.|
|Stop(String, String)||Stops a listener for a connection specified in a previous Start call.|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
is ideal for caching scenarios, where your ASP.NET application or middle-tier service needs to keep certain information cached in memory. 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 object to one or more SqlCommand objects. To receive notifications, you need to subscribe to the OnChange event. For more information about the requirements for creating queries for notifications, see "Creating a Query for Notification" in SQL Server Books Online.
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 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 Planning for Notifications topic in SQL Server Books Online.
requires the .NET Framework version 2.0 and SQL Server 2005. For more information, see Query Notifications in SQL Server (ADO.NET) and "Building Notification Solutions" in SQL Server Books Online.
The 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 2005 Books Online
SQL Server 2008 Books Online
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.