Language

SqlDataSource.SqlCacheDependency プロパティ

定義

Microsoft SQL Server キャッシュの依存関係に使用するデータベースとテーブルを示すセミコロン区切りの文字列を取得または設定します。

public:
 virtual property System::String ^ SqlCacheDependency { System::String ^ get(); void set(System::String ^ value); };
public virtual string SqlCacheDependency { get; set; }
member this.SqlCacheDependency : string with get, set
Public Overridable Property SqlCacheDependency As String

プロパティ値

SQL Server キャッシュの依存関係に使用するデータベースとテーブルを示す文字列。

例

次のコード例では、SQL Server キャッシュの依存関係を作成し、SqlCacheDependency コントロールのSqlDataSource プロパティを設定する方法を示します。 この例では、データベースは 120 秒ごとにポーリングされます。 その間に Northwind Traders Employees テーブルのデータが変更された場合、 SqlDataSource コントロールによってキャッシュされ、 GridView コントロールによって表示されるデータは、次にデータベースがポーリングされるときに、 SqlDataSource コントロールによって更新されます。

<%@ Page language="c#" %>

<!--

The page uses an example configuration that includes
connection strings and a defined SqlCacheDependecy.

<?xml version="1.0"?>
<configuration>

  <connectionStrings>
    <add name="MyNorthwind"
         connectionString="Data Source="localhost";Integrated Security="SSPI";Initial Catalog="Northwind""
         providerName="System.Data.SqlClient" />
  </connectionStrings>

  <system.web>
    <caching>
      <sqlCacheDependency enabled="true">
        <databases>
          <add
            name="Northwind"
            connectionStringName="MyNorthwind"
            pollTime="120000" />
        </databases>
      </sqlCacheDependency>
    </caching>

  </system.web>
</configuration>
-->

<!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">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="Form1" method="post" runat="server">

        <asp:gridview
          id="GridView1"
          runat="server"
          datasourceid="SqlDataSource1" />

        <asp:sqldatasource
          id="SqlDataSource1"
          runat="server"
          connectionstring="<%$ ConnectionStrings:MyNorthwind%>"
          selectcommand="SELECT EmployeeID,FirstName,Lastname FROM Employees"
          enablecaching="True"
          cacheduration="300"
          cacheexpirationpolicy="Absolute"
          sqlcachedependency="Northwind:Employees" />

    </form>
  </body>
</html>
<%@ Page language="vb" %>

<!--

The page uses an example configuration that includes
connection strings and a defined SqlCacheDependecy.

<?xml version="1.0"?>
<configuration>

  <connectionStrings>
    <add name="MyNorthwind"
         connectionString="Data Source="localhost";Integrated Security="SSPI";Initial Catalog="Northwind""
         providerName="System.Data.SqlClient" />
  </connectionStrings>

  <system.web>
    <caching>
      <sqlCacheDependency enabled="true">
        <databases>
          <add
            name="Northwind"
            connectionStringName="MyNorthwind"
            pollTime="120000" />
        </databases>
      </sqlCacheDependency>
    </caching>

  </system.web>
</configuration>
-->

<!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">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="Form1" method="post" runat="server">

        <asp:gridview
          id="GridView1"
          runat="server"
          datasourceid="SqlDataSource1" />

        <asp:sqldatasource
          id="SqlDataSource1"
          runat="server"
          connectionstring="<%$ ConnectionStrings:MyNorthwind%>"
          selectcommand="SELECT EmployeeID,FirstName,Lastname FROM Employees"
          enablecaching="True"
          cacheduration="300"
          cacheexpirationpolicy="Absolute"
          sqlcachedependency="Northwind:Employees" />

    </form>
  </body>
</html>

注釈

SqlDataSource コントロールは、データ キャッシュのSqlCacheDependency オブジェクトに基づくオプションの有効期限ポリシーをサポートします (サービスはデータベース サーバー用に構成する必要があります)。

SqlCacheDependency文字列は、@ Page ディレクティブで使用されるのと同じ形式に従ってデータベースとテーブルを識別します。文字列の最初の部分は、Microsoft SQL Server データベースへの接続文字列、コロン区切り記号、最後にデータベース テーブルの名前 ("connectionstring1:table1" など) です。 SqlCacheDependency プロパティが複数のテーブルに依存している場合、接続文字列とテーブル名のペアはセミコロン ("connectionstring1:table1";connectionstring2:table2" など) で区切られます。

Important

Microsoft Windows 認証でクライアントの偽装を使用している場合、最初のユーザーがデータにアクセスすると、データがキャッシュされます。 別のユーザーが同じデータを要求した場合、データはキャッシュから取得されます。 データは、ユーザーがデータにアクセスすることを確認するためにデータベースを別の呼び出しを行うことによって取得されません。 複数のユーザーがデータにアクセスすることが予想され、データベースのセキュリティ構成によってデータを取得するたびに検証されるようにする場合は、キャッシュを使用しないでください。

適用対象

こちらもご覧ください