Export (0) Print
Expand All

SqlDependency Class

Note: This class is new in the .NET Framework version 2.0.

The SqlDependency object represents a query notification dependency between an application and an instance of SQL Server 2005. An application can create a SqlDependency object and register to receive notifications via the OnChangeEventHandler event handler.

Namespace: System.Data.SqlClient
Assembly: System.Data (in system.data.dll)

public sealed class SqlDependency
public final class SqlDependency
public final class SqlDependency

SqlDependency is ideal for caching scenarios, where your ASP.NET application or middle-tier service needs to keep certain information cached in memory. 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 SqlDependency 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.

NoteNote

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 SqlDependency objects set up for a single database server.

SqlDependency requires the .NET Framework version 2.0 and SQL Server 2005. For more information, see Using Query Notifications and "Building Notification Solutions" in SQL Server Books Online.

NoteNote

The OnChange event may be generated on a different thread from the thread that initiated command execution. For more information and examples, see Using SqlDependency in a Windows Application.

System.Object
  System.Data.SqlClient.SqlDependency

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft