SqlCacheDependencyAdmin クラス
アセンブリ: System.Web (system.web.dll 内)


このクラスのメソッドを使用して、SQL Server データベースとそのテーブルの SqlCacheDependency オブジェクトの変更通知をプログラムによって有効にしたり、無効にしたりできます。また、このクラスは GetTablesEnabledForNotifications メソッドを使用して、変更通知が有効になっているデータベース テーブル内のテーブルに関する情報を取得します。Aspnet_regsql コマンド ライン ツールを使用して、SQL Server データベースとそのテーブルの変更通知を管理することもできます。
![]() |
---|
このクラスからメソッドを呼び出すには、SQL Server データベースへのアクセスで使用するアカウントに、テーブルおよびストアド プロシージャを作成できる権限が必要です。特定のテーブルで通知を有効にするには、そのテーブルで SQL Server トリガを作成できる権限が必要です。データベースの権限の設定方法の詳細については、SQL Server のドキュメントを参照してください。ASP.NET プロセスで使用されるアカウントの詳細については、「ASP.NET の偽装」を参照してください。 |

SQL Server データベース テーブルの変更通知を有効または無効にする、単純な ASP.NET ページのコード例を次に示します。これは SqlCacheDependencyAdmin オブジェクトを使用して、接続文字列 MyConnectionString で指定されているデータベースの変更通知を管理します。この例では、ユーザー インターフェイスを定義する .aspx ファイルと、ASP.NET イベントのソース コードを含む分離コード ファイルの 2 つのファイルが示されています。
最初のサンプルは、ユーザー インターフェイスを定義する .aspx ファイルを示します。
<%@ 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 > <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <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>
2 番目のサンプルは、ページ イベントのソース コードを含む分離コード ファイルを示します。
Partial Class cacheDependencyAdminvb Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) 'Put the page into a default state. enabledTables.Visible = True disableTable.Visible = True enabledTablesMsg.Text = "Tables enabled for change notification:" tableName.Visible = True enableTable.Visible = True tableEnableMsg.Text = "Enable change notification on table(s):" enableTableErrorMsg.Text = "" End Sub Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Try Dim enabledTablesList As String() enabledTablesList = SqlCacheDependencyAdmin.GetTablesEnabledForNotifications( _ ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString) If enabledTablesList.Length > 0 Then enabledTables.DataSource = enabledTablesList enabledTables.DataBind() Else enabledTablesMsg.Text = "No tables are enabled for change notifications." enabledTables.Visible = False disableTable.Visible = False End If Catch ex As DatabaseNotEnabledForNotificationException enabledTables.Visible = False disableTable.Visible = False enabledTablesMsg.Text = "Cache notifications are not enabled in this database." tableName.Visible = False enableTable.Visible = False tableEnableMsg.Text = "Must enable database for notifications before enabling tables." End Try End Sub Protected Sub enableNotification_Click(ByVal sender As Object, ByVal e As System.EventArgs) SqlCacheDependencyAdmin.EnableNotifications( _ ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString) End Sub Protected Sub disableNotification_Click(ByVal sender As Object, ByVal e As System.EventArgs) SqlCacheDependencyAdmin.DisableNotifications( _ ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString) End Sub Protected Sub disableTable_Click(ByVal sender As Object, ByVal e As System.EventArgs) For Each item As ListItem In enabledTables.Items If item.Selected Then SqlCacheDependencyAdmin.DisableTableForNotifications( _ ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString, _ item.Text) End If Next End Sub Protected Sub enableTable_Click(ByVal sender As Object, ByVal e As System.EventArgs) Try If tableName.Text.Contains(";") Then Dim tables As String() tables = tableName.Text.Split(New [Char]() {";"c}) For i As Integer = 0 To tables.Length - 1 tables(i) = tables(i).Trim Next SqlCacheDependencyAdmin.EnableTableForNotifications( _ ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString, _ tables) Else SqlCacheDependencyAdmin.EnableTableForNotifications( _ ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString, _ tableName.Text) End If Catch ex As HttpException enableTableErrorMsg.Text = "<br />" & _ "An error occured enabling a table.<br />" & _ "The error message was: " & _ ex.Message enableTableErrorMsg.Visible = True End Try End Sub End Class
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Web.Caching; public partial class cacheDependencyAdmincs : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // Put page in default state. enabledTables.Visible = true; disableTable.Visible = true; enabledTablesMsg.Text = "Tables enabled for change notification:"; tableName.Visible = true; enableTable.Visible = true; tableEnableMsg.Text = "Enable change notification on table(s):"; enableTableErrorMsg.Visible = false; } protected void Page_PreRender(object sender, EventArgs e) { try { string[] enabledTablesList = SqlCacheDependencyAdmin.GetTablesEnabledForNotifications( ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString); if (enabledTablesList.Length > 0) { enabledTables.DataSource = enabledTablesList; enabledTables.DataBind(); } else { enabledTablesMsg.Text = "No tables are enabled for change notifications."; enabledTables.Visible = false; disableTable.Visible = false; } } catch (DatabaseNotEnabledForNotificationException ex) { enabledTables.Visible = false; disableTable.Visible = false; enabledTablesMsg.Text = "Cache notifications are not enabled in this database."; tableName.Visible = false; enableTable.Visible = false; tableEnableMsg.Text = "Must enable database for notifications before enabling tables"; } } protected void enableNotification_Click(object sender, EventArgs e) { SqlCacheDependencyAdmin.EnableNotifications( ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString); } protected void disableNotification_Click(object sender, EventArgs e) { SqlCacheDependencyAdmin.DisableNotifications( ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString); } protected void disableTable_Click(object sender, EventArgs e) { foreach (ListItem item in enabledTables.Items) { if (item.Selected) { SqlCacheDependencyAdmin.DisableTableForNotifications( ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString , item.Text); } } } protected void enableTable_Click(object sender, EventArgs e) { try { if (tableName.Text.Contains(";")) { string[] tables = tableName.Text.Split(new Char[] { ';' }); for (int i = 0; i < tables.Length; i++) tables[i] = tables[i].Trim(); SqlCacheDependencyAdmin.EnableTableForNotifications( ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString , tables); } else { SqlCacheDependencyAdmin.EnableTableForNotifications( ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString , tableName.Text); } } catch (HttpException ex) { enableTableErrorMsg.Text = "<br />" + "An error occured enabling a table.<br />" + "The error message was: " + ex.Message; enableTableErrorMsg.Visible = true; } } }

System.Web.Caching.SqlCacheDependencyAdmin


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


SqlCacheDependencyAdmin メソッド

名前 | 説明 | |
---|---|---|
![]() | DisableNotifications | 指定されているデータベースの SqlCacheDependency 変更通知を無効にします。 |
![]() | DisableTableForNotifications | オーバーロードされます。 SQL Server データベース テーブルまたはデータベース テーブルの配列の SqlCacheDependency 変更通知を無効にします。 |
![]() | EnableNotifications | 指定されているデータベースの SqlCacheDependency 変更通知を有効にします。 |
![]() | EnableTableForNotifications | オーバーロードされます。 SQL Server データベースに接続し、データベース テーブルまたはテーブルの SqlCacheDependency 変更通知を準備します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetTablesEnabledForNotifications | 変更通知が有効になっている、SQL Server データベース内の各テーブルの名前を含む文字列配列を取得します。 |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

SqlCacheDependencyAdmin メンバ
ポーリング ベースの依存関係を使用するときに、SqlCacheDependency クラスをサポートするために SQL Server データベースで必要な管理タスクを実行します。このクラスは継承できません。
SqlCacheDependencyAdmin データ型で公開されるメンバを以下の表に示します。

名前 | 説明 | |
---|---|---|
![]() | DisableNotifications | 指定されているデータベースの SqlCacheDependency 変更通知を無効にします。 |
![]() | DisableTableForNotifications | オーバーロードされます。 SQL Server データベース テーブルまたはデータベース テーブルの配列の SqlCacheDependency 変更通知を無効にします。 |
![]() | EnableNotifications | 指定されているデータベースの SqlCacheDependency 変更通知を有効にします。 |
![]() | EnableTableForNotifications | オーバーロードされます。 SQL Server データベースに接続し、データベース テーブルまたはテーブルの SqlCacheDependency 変更通知を準備します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetTablesEnabledForNotifications | 変更通知が有効になっている、SQL Server データベース内の各テーブルの名前を含む文字列配列を取得します。 |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

Weblioに収録されているすべての辞書からSqlCacheDependencyAdminを検索する場合は、下記のリンクをクリックしてください。

- SqlCacheDependencyAdminのページへのリンク