SqlDataSource.SqlCacheDependency Propriedade

Definição

Obtém ou define uma cadeia de caracteres separada por ponto-e-vírgula que indica quais bancos de dados e tabelas usar para a dependência de cache do Microsoft SQL Server.Gets or sets a semicolon-delimited string that indicates which databases and tables to use for the Microsoft SQL Server cache dependency.

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

Valor da propriedade

String

Uma cadeia de caracteres que indica quais bancos de dados e tabelas usar para a dependência de cache do SQL Server.A string that indicates which databases and tables to use for the SQL Server cache dependency.

Exemplos

O exemplo de código a seguir demonstra como criar uma dependência de cache SQL Server e definir a SqlCacheDependency propriedade de um SqlDataSource controle.The following code example demonstrates how to create a SQL Server cache dependency and set the SqlCacheDependency property of a SqlDataSource control. Neste exemplo, o banco de dados é sondado a cada 120 segundos.In this example, the database is polled every 120 seconds. Se os dados na tabela funcionários da Northwind Traders forem alterados durante esse tempo, todos os dados armazenados em cache pelo SqlDataSource controle e exibidos pelo controle GridView serão atualizados pelo SqlDataSource controle na próxima vez que o banco de dados for sondado.If the data in the Northwind Traders Employees table changes during that time, any data that is cached by the SqlDataSource control and displayed by the GridView control is refreshed by the SqlDataSource control the next time the database is polled.

<%@ 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>

Comentários

O SqlDataSource controle dá suporte a uma política de expiração opcional com base no SqlCacheDependency objeto para o cache de dados (o serviço deve ser configurado para o servidor de banco de dado).The SqlDataSource control supports an optional expiration policy based on the SqlCacheDependency object for the data cache (the service must be configured for the database server).

A SqlCacheDependency cadeia de caracteres identifica bancos de dados e tabelas de acordo com o mesmo formato usado pela @ Page diretiva, em que a primeira parte da cadeia de caracteres é uma cadeia de conexão para um Microsoft SQL Server banco de dados, seguida por um delimitador de dois-pontos e, finalmente, o nome da tabela de banco de dados (por exemplo, "connectionstring1:table1" ).The SqlCacheDependency string identifies databases and tables according to the same format that is used by the @ Page directive, where the first part of the string is a connection string to a Microsoft SQL Server database, followed by a colon delimiter, and finally the name of the database table (for example, "connectionstring1:table1"). Se a SqlCacheDependency Propriedade depender de mais de uma tabela, os pares de nomes de cadeia de caracteres de conexão e de tabela serão separados por ponto-e-vírgula (por exemplo, "connectionstring1:table1";connectionstring2:table2" ).If the SqlCacheDependency property depends on more than one table, the connection string-and-table name pairs are separated by semicolons (for example, "connectionstring1:table1";connectionstring2:table2").

Importante

Quando você estiver usando a representação de cliente na autenticação do Microsoft Windows, os dados serão armazenados em cache quando o primeiro usuário acessar os dados.When you are using client impersonation under Microsoft Windows authentication, the data is cached when the first user accesses the data. Se outro usuário solicitar os mesmos dados, os dados serão recuperados do cache.If another user requests the same data, the data is retrieved from the cache. Os dados não são recuperados fazendo outra chamada para o banco de dados para verificar o acesso do usuário a eles.The data is not retrieved by making another call to the database to verify the user's access to the data. Se você esperar que mais de um usuário acesse os dados e desejar que cada recuperação dos dados seja verificada pelas configurações de segurança do banco de dado, não use o Caching.If you expect more than one user to access the data, and you want each retrieval to the data to be verified by the security configurations for the database, do not use caching.

Aplica-se a

Confira também