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.
Assembly: System.Web (in System.Web.dll)
The SqlCacheDependencyAdmin type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() | DisableNotifications | Disables SqlCacheDependency change notifications for the specified database. |
![]() ![]() | DisableTableForNotifications(String, String) | Disables SqlCacheDependency change notifications on a SQL Server database table. |
![]() ![]() | DisableTableForNotifications(String, array<String>) | Disables SqlCacheDependency change notifications on an array of SQL Server database tables. |
![]() ![]() | EnableNotifications | Enables SqlCacheDependency change notifications on the specified database. |
![]() ![]() | EnableTableForNotifications(String, String) | Connects to the specified SQL Server database and enables the specified database table for SqlCacheDependency change notifications. |
![]() ![]() | EnableTableForNotifications(String, array<String>) | Connects to the specified SQL Server database and enables the specified array of database tables for SqlCacheDependency change notification. |
![]() ![]() | GetTablesEnabledForNotifications | Retrieves 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.
Note |
|---|
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 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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html" /> <title>Cache Dependency Administration</title> </head> <body> <form id="form1" runat="server"> <table> <tr> <td colspan="2"> Database support for change notifications: </td> </tr> <tr> <td align="center"> <asp:Button ID="enableNotification" runat="server" Text="On" OnClick="enableNotification_Click" /> </td> <td align="center"> <asp:Button ID="disableNotification" runat="server" Text="Off" OnClick="disableNotification_Click" /> </td> </tr> <tr> <td colspan="2"> <asp:Label ID="enabledTablesMsg" runat="server" Text="Tables enabled for change notification:" /> </td> </tr> <tr> <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> </tr> <tr> <td colspan="2"> <asp:Label ID="tableEnableMsg" runat="server" Text="Enable change notification on table:" /> </td> </tr> <tr> <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" /> </td> </tr> </table> </form> </body> </html>
The second sample is the code-behind file containing the source code for the page events.
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.


Note
Security Note