.NET Framework Class Library SqlDependency Class 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.

Inheritance Hierarchy
Namespace:
System.Data.SqlClient
Assembly:
System.Data (in System.Data.dll)

Syntax
Public NotInheritable Class SqlDependency
public sealed class SqlDependency
public ref class SqlDependency sealed
[<Sealed>]
type SqlDependency = class end
The SqlDependency type exposes the following members.

Constructors

Events
|
| Name | Description |
|---|
.gif) | OnChange | Occurs when a notification is received for any of the commands associated with this SqlDependency object. | Top

Remarks
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. Note |
|---|
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 Query Notifications in SQL Server (ADO.NET) and "Building Notification Solutions" in SQL Server Books Online. Note |
|---|
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.

Version Information
.NET FrameworkSupported in: 4, 3.5, 3.0, 2.0 .NET Framework Client ProfileSupported in: 4, 3.5 SP1

Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), 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.

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

See Also
|
Biblioteca de clases de .NET Framework SqlDependency (Clase) El objeto SqlDependency representa una dependencia de notificación de consulta entre una aplicación y una instancia de SQL Server 2005. Una aplicación puede crear un objeto SqlDependency y registrarlo para recibir notificaciones a través del controlador de eventos OnChangeEventHandler.

Jerarquía de herencia
Espacio de nombres:
System.Data.SqlClient
Ensamblado:
System.Data (en System.Data.dll)

Sintaxis
Public NotInheritable Class SqlDependency
public sealed class SqlDependency
public ref class SqlDependency sealed
[<Sealed>]
type SqlDependency = class end
El tipo SqlDependency expone los siguientes miembros.

Constructores

Eventos
|
| Nombre | Descripción |
|---|
.gif) | OnChange | Se produce al recibir una notificación para cualquiera de los comandos asociados a este objeto SqlDependency. | Arriba

Comentarios
SqlDependency es ideal para almacenar escenarios en memoria caché cuando la aplicación ASP.NET o el servicio de nivel medio necesitan mantener determinada información almacenada en memoria caché. SqlDependency le permite recibir las notificaciones cuando los datos originales de la base de datos cambian para que la memoria caché pueda estar actualizada. Para establecer una dependencia, es necesario asociar un objeto SqlDependency a uno o varios objetos SqlCommand. Para recibir notificaciones, es necesario suscribirse al evento OnChange. Para obtener más información sobre los requisitos para crear consultas para las notificaciones, vea "Creating a Query for Notification" en los Libros en pantalla de SQL Server. Nota |
|---|
La clase SqlDependency se ha diseñado para utilizarla en ASP.NET o en los servicios de nivel medio donde hay un número relativamente pequeño de servidores con dependencias activas a la base de datos. No está diseñada para usarla en aplicaciones cliente, en las que cientos o miles de equipos cliente tendrían establecidos objetos SqlDependency para un único servidor de bases de datos. |
SqlDependency requiere la versión 2.0 de .NET Framework y SQL Server 2005. Para obtener más información, vea Notificaciones de consulta en SQL Server (ADO.NET) y "Building Notification Solutions" en los Libros en pantalla de SQL Server. Nota |
|---|
El evento OnChange se puede generar en un subproceso diferente del que inició la ejecución de comandos. |
Las notificaciones de consulta solo son compatibles con las instrucciones SELECT que cumplen ciertos requisitos específicos. En la tabla siguiente se proporcionan vínculos a la documentación sobre Service Broker y las notificaciones de consulta de los Libros en pantalla de SQL Server.

Información de versión
.NET FrameworkCompatible con: 4, 3.5, 3.0, 2.0 .NET Framework Client ProfileCompatible con: 4, 3.5 SP1

Plataformas
Windows 7, Windows Vista SP1 o posterior, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (no se admite Server Core), Windows Server 2008 R2 (se admite Server Core con SP1 o posterior), Windows Server 2003 SP2
.NET Framework no admite todas las versiones de todas las plataformas. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

Seguridad para subprocesos
Todos los miembros static ( Shared en Visual Basic) públicos de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.

Vea también
|