请单击以进行评分并提供反馈
MSDN
MSDN Library
.NET 开发
.NET Framework
 SqlCacheDependency 属性
全部折叠/全部展开 全部折叠
此页面仅适用于
Microsoft Visual Studio 2008/.NET Framework 3.5

同时提供下列产品的其他版本:
.NET Framework 类库
SqlDataSource..::.SqlCacheDependency 属性

更新:2007 年 11 月

获取或设置一个用分号分隔的字符串,指示用于 Microsoft SQL Server 缓存依赖项的数据库和表。

命名空间:  System.Web.UI.WebControls
程序集:  System.Web(在 System.Web.dll 中)

Visual Basic(声明)
Public Overridable Property SqlCacheDependency As String
Visual Basic (用法)
Dim instance As SqlDataSource
Dim value As String

value = instance.SqlCacheDependency

instance.SqlCacheDependency = value
C#
public virtual string SqlCacheDependency { get; set; }
Visual C++
public:
virtual property String^ SqlCacheDependency {
    String^ get ();
    void set (String^ value);
}
J#
/** @property */
public String get_SqlCacheDependency()
/** @property */
public  void set_SqlCacheDependency(String value)
JScript
public function get SqlCacheDependency () : String
public function set SqlCacheDependency (value : String)
ASP.NET
<asp:SqlDataSource SqlCacheDependency="String" />

属性值

类型:System..::.String

一个字符串,指示用于 SQL Server 缓存依赖项的数据库和表。

SqlDataSource 控件支持一个可选的过期策略,该策略基于数据缓存(必须为数据库服务器配置了该服务)的 SqlCacheDependency 对象。

SqlCacheDependency 字符串根据 @ Page 指令所用的格式来标识数据库和表,其中,字符串的第一部分是用于连接 Microsoft SQL Server 数据库的连接字符串,连接字符串后面是一个冒号分隔符,最后是数据库表的名称(例如 "connectionstring1:table1")。如果 SqlCacheDependency 属性依赖于多个表,则由连接字符串和表名组成的各对之间以分号分隔(例如 "connectionstring1:table1";connectionstring2:table2")。

安全说明:

在 Microsoft Windows 身份验证下使用客户端模拟时,数据在第一个用户访问它时被缓存。如果另一个用户请求同一数据,则会从缓存中检索该数据。对数据库执行另一个调用以验证用户对数据有访问权限时不会检索数据。如果希望数据可由多个用户访问,并且要求数据库的安全配置验证每个对数据的检索,请不要使用缓存。

下面的代码示例演示如何创建 SQL Server 缓存依赖项并设置 SqlDataSource 控件的 SqlCacheDependency 属性。在此示例中,每隔 120 秒轮询一次数据库。如果 Northwind Traders Employees 表中的数据在该时间间隔内发生更改,则在下一次轮询数据库时,SqlDataSource 控件会刷新 SqlDataSource 控件缓存的所有数据和 GridView 控件所显示的所有数据。

Visual Basic
<%@ 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>
    <cache>
      <sqlCacheDependency enabled="true">
        <databases>
          <add
            name="Northwind"
            connectionStringName="MyNorthwind"
            pollTime="120000" />
        </databases>
      </sqlCacheDependency>
    </cache>

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
  <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>
C#
<%@ 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>
    <cache>
      <sqlCacheDependency enabled="true">
        <databases>
          <add
            name="Northwind"
            connectionStringName="MyNorthwind"
            pollTime="120000" />
        </databases>
      </sqlCacheDependency>
    </cache>

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
  <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>
J#
<%@ Page language="VJ#" %>

<!--

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

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

  <connectionStrings>
    <add name = "NorthwindConnection" connectionString = "Data Source="localhost";Integrated Security="SSPI";Initial Catalog="Northwind"" />
  </connectionStrings>

  <system.web>

    ...

    <cache>
      <sqlCacheDependency enabled="true">
        <databases>
          <add
            name="Northwind_Remote"
            connectionStringName="NorthwindConnection"
            pollTime="120000" />
        </databases>
      </sqlCacheDependency>
    </cache>

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
  <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="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind"
          selectcommand="SELECT EmployeeID,FirstName,Lastname FROM Employees"
          enablecaching="True"
          cacheduration="300"
          cacheexpirationpolicy="Absolute"
          sqlcachedependency="Northwind_Remote:Employees" />

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

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

.NET Framework

受以下版本支持:3.5、3.0、2.0
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
© 2009 Microsoft Corporation 版权所有。 保留所有权利 | 商标 | 隐私权声明
Page view tracker