This documentation is archived and is not being maintained.

SqlCacheDependencyAdmin Class

Performs administrative tasks required on a SQL Server database to support the SqlCacheDependency class when using polling-based dependencies. This class cannot be inherited.


Namespace:  System.Web.Caching
Assembly:  System.Web (in System.Web.dll)

[<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.High)>]
type SqlCacheDependencyAdmin =  class end

The SqlCacheDependencyAdmin type exposes the following members.

Public methodStatic memberDisableNotificationsDisables SqlCacheDependency change notifications for the specified database.
Public methodStatic memberDisableTableForNotifications(String, String)Disables SqlCacheDependency change notifications on a SQL Server database table.
Public methodStatic memberDisableTableForNotifications(String, String[])Disables SqlCacheDependency change notifications on an array of SQL Server database tables.
Public methodStatic memberEnableNotificationsEnables SqlCacheDependency change notifications on the specified database.
Public methodStatic memberEnableTableForNotifications(String, String)Connects to the specified SQL Server database and enables the specified database table for SqlCacheDependency change notifications.
Public methodStatic memberEnableTableForNotifications(String, String[])Connects to the specified SQL Server database and enables the specified array of database tables for SqlCacheDependency change notification.
Public methodStatic memberGetTablesEnabledForNotificationsRetrieves a string array containing the name of every table that is enabled for change notifications in a SQL Server database.

You can use the methods of this class to programmatically enable and disable a SQL Server database and its tables for SqlCacheDependency object change notifications. In addition, this class obtains information about which tables in a database are enabled for change notifications using the GetTablesEnabledForNotifications method. However, you can also use the Aspnet_regsql command-line tool to manage change notifications for a SQL Server database and its tables.


To call any of the methods in this class, the account you use to access the SQL Server database must have permissions to create tables and stored procedures. To enable notifications on a specific table, you must have permissions to create a SQL Server trigger on that table. For more information on how to set permissions on a database, see the SQL Server documentation. For more information about the account used by the ASP.NET process, see ASP.NET Impersonation.

The following code example is a simple ASP.NET page for enabling and disabling change notifications on SQL Server database tables. It uses the SqlCacheDependencyAdmin object to manage change notifications in the database specified in a connection string called MyConnectionString. The example includes two files, an .aspx file that defines the user interface and a code-behind file containing the source code for the ASP.NET events.

The first sample is the .aspx file that defines the user interface.

Security noteSecurity Note

This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="cacheDependencyAdmincs.aspx.cs"
  Inherits="cacheDependencyAdmincs" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
  <meta http-equiv="Content-Type" content="text/html" />
  <title>Cache Dependency Administration</title>
  <form id="form1" runat="server">
        <td colspan="2">
          Database support for change notifications:
        <td align="center">
          <asp:Button ID="enableNotification" runat="server" Text="On" OnClick="enableNotification_Click" />
        <td align="center">
          <asp:Button ID="disableNotification" runat="server" Text="Off" OnClick="disableNotification_Click" />
        <td colspan="2">
          <asp:Label ID="enabledTablesMsg" runat="server" Text="Tables enabled for change notification:" />
        <td colspan="2">
          <asp:ListBox ID="enabledTables" runat="server" SelectionMode="multiple" /><br />
          <asp:Button ID="disableTable" runat="server" Text="Disable selected table(s)" OnClick="disableTable_Click" />
        <td colspan="2">
          <asp:Label ID="tableEnableMsg" runat="server" Text="Enable change notification on table:" />
        <td colspan="2">
          <asp:TextBox ID="tableName" runat="server" /><br />
          <asp:Button ID="enableTable" runat="server" Text="Enable table(s)" OnClick="enableTable_Click" />
          <asp:Label id="enableTableErrorMsg" runat="server" Visible="false" />

The second sample is the code-behind file containing the source code for the page events.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

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.

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