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)
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.
- AspNetHostingPermission
for operating in a hosted environment. Demand value: LinkDemand; Permission value: High.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note:
Security Note: