SqlCacheDependency コンストラクタ (String, String)
アセンブリ: System.Web (system.web.dll 内)

Dim databaseEntryName As String Dim tableName As String Dim instance As New SqlCacheDependency(databaseEntryName, tableName)

例外の種類 | 条件 |
---|---|
HttpException | SqlClientPermission の内部検証が失敗しました。 または テーブル ベースの通知用に設定されているデータベースの一覧に databaseEntryName がありませんでした。 または 初期化時に SqlCacheDependency オブジェクトをデータベースに接続できませんでした。 または SqlCacheDependency オブジェクトをサポートするデータベース ストアド プロシージャまたはデータベースのいずれかで、SqlCacheDependency オブジェクトが権限拒否エラーを検出しました。 |
ArgumentException | tableName パラメータが String.Empty です。 |
ConfigurationErrorsException | SqlCacheDependency でポーリングが有効になっていません。 または または アプリケーションの構成ファイルで接続文字列が指定されませんでした。 または アプリケーションの構成ファイルで指定されている接続文字列が見つかりませんでした。 または |
DatabaseNotEnabledForNotificationException | |
TableNotEnabledForNotificationException | |
ArgumentNullException | databaseEntryName が null 参照 (Visual Basic では Nothing) です。 または tableName が null 参照 (Visual Basic では Nothing) です。 |

このコンストラクタを使用して、SQL Server 7 製品および SQL Server 2000 製品の SqlCacheDependency オブジェクトを作成します。
database パラメータに渡されるデータベース名は、アプリケーションの Web.config ファイルで定義されている必要があります。例として、pubs というデータベースの SqlCacheDependency 変更通知を定義する Web.config ファイルを次に示します。
<configuration> <connectionStrings> <add name="Pubs" connectionString="Data Source=(local); Initial Catalog=pubs; Integrated Security=true"; providerName="System.Data.SqlClient" /> </connectionStrings> <system.web> <caching> <sqlCacheDependency enabled = "true" pollTime = "60000" > <databases> <add name="pubs" connectionString = "pubs" pollTime = "9000000" /> </databases> </sqlCacheDependency> </caching> </system.web> </configuration>
このコンストラクタを使用する場合は、DatabaseNotEnabledForNotificationException および TableNotEnabledForNotificationException という 2 つの例外がスローされるのが一般的です。DatabaseNotEnabledForNotificationException がスローされた場合は、例外処理コードで SqlCacheDependencyAdmin.EnableNotifications メソッドを呼び出すか、コマンド ライン ツールの Aspnet_regsql.exe を使用して、データベースの通知を設定します。TableNotEnabledForNotificationException がスローされた場合は、SqlCacheDependencyAdmin.EnableTableForNotifications メソッドを呼び出すか、Aspnet_regsql.exe を使用して、テーブルの通知を設定します。

このコンストラクタを使用して、SQL Server データベース (Northwind) のデータベース テーブル (Categories) に関連付けられている SqlCacheDependency クラスのインスタンスを作成するコード例を次に示します。
Sub Page_Load(Src As Object, E As EventArgs) ' Declare the SqlCacheDependency instance, SqlDep. Dim SqlDep As SqlCacheDependency ' Check the Cache for the SqlSource key. ' If it isn't there, create it with a dependency ' on a SQL Server table using the SqlCacheDependency class. If Cache("SqlSource") Is Nothing ' Because of possible exceptions thrown when this ' code runs, use Try...Catch...Finally syntax. Try ' Instantiate SqlDep using the SqlCacheDependency constructor. SqlDep = New SqlCacheDependency("Northwind", "Categories") ' Handle the DatabaseNotEnabledForNotificationException with ' a call to the SqlCacheDependencyAdmin.EnableNotifications method. Catch exDBDis As DatabaseNotEnabledForNotificationException Try SqlCacheDependencyAdmin.EnableNotifications("Northwind") ' If the database does not have permissions set for creating tables, ' the UnauthorizedAccessException is thrown. Handle it by redirecting ' to an error page. Catch exPerm As UnauthorizedAccessException Response.Redirect(".\ErrorPage.htm") End Try ' Handle the TableNotEnabledForNotificationException with ' a call to the SqlCacheDependencyAdmin.EnableTableForNotifications method. Catch exTabDis As TableNotEnabledForNotificationException Try SqlCacheDependencyAdmin.EnableTableForNotifications( _ "Northwind", "Categories") ' If a SqlException is thrown, redirect to an error page. Catch exc As SqlException Response.Redirect(".\ErrorPage.htm") End Try ' If all the other code is successful, add MySource to the Cache ' with a dependency on SqlDep. If the Categories table changes , ' MySource will be removed from the Cache. Then generate a message ' that the data is newly created and added to the cache. Finally Cache.Insert("SqlSource", Source1, SqlDep) CacheMsg.Text = "The data object was created explicitly." End Try Else CacheMsg.Text = "The data was retrieved from the Cache." End If End Sub

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


SqlCacheDependency コンストラクタ (SqlCommand)
アセンブリ: System.Web (system.web.dll 内)



このコンストラクタは、SQL Server 2005 製品のクエリ通知機能を使用する SqlCacheDependency オブジェクトの作成に使用します。
sqlCommand パラメータに関連付けられている SQL ステートメントには、次の要素が含まれる必要があります。
-
たとえば、データベース所有者に所有されている "customers" という名前のテーブルを参照するには、SQL ステートメントは "dbo.customers" を参照する必要があります。
-
SELECT ステートメント内の明示的な列名。アスタリスク (*) のワイルドカード文字を使用して、テーブルのすべての列を選択することはできません。
たとえば、"select * from customers" の代わりに "select name, address, city, state from dbo.customers" を使用する必要があります。
このコンストラクタによって、SQL Server 2005 のクエリ通知を使用してページ レベルの出力キャッシュを行うページ上の SqlCacheDependency インスタンスと SqlCommand インスタンスを関連付けることはできません。

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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

- SqlCacheDependency コンストラクタのページへのリンク