To use the SQL data cache dependency function, perform the following three steps:
1. Configure the SQL Server database to enable the SQL database cache dependency support
How to implement this step: 1: You can use the "Visual Studio 2005 command prompt": if you do not understand the configuration, you can use apsnet_regsql.exe -? Command to view help documentation
// Enable the database dependency Function
Aspnet_regsql.exe-s localhost-U sa-P Sa-D database name-ed
// Enable the dependency function of the database table
Aspnet_regsql.exe-s localhost-U sa-P Sa-D database name-T table name-et
// Disable the data cache dependency function of the database
Aspnet_regsql.exe-s localhost-U sa-P Sa-D database name-dd
// Disable the data cache dependency function of a data table
Aspnet_regsql.exe-s localhost-U sa-P Sa-D database name-T table name-dt
2: Use the sqlcachedependencyadmin class to implement the same configuration function
Ii. Configure the Web. config file
<Configuration>
<Appsettings/>
<Connectionstrings>
<Add Name = "pubsconnectionstring "Connectionstring =" Data Source = wangxiaojun; initial catalog = pubs; Integrated Security = true"
Providername = "system. Data. sqlclient"/>
</Connectionstrings>
<System. Web>
<Caching>
<Sqlcachedependency enabled = "true" polltime = "600">
<Databases>
<Add name = "pubs" connectionstringname = "pubsconnectionstring"/>
</Databases>
</Sqlcachedependency>
</Caching>
</System. Web>
</Configuration>
Iii. Implementation of specific applications Program , Using the SQL data cache dependency Function
Use
<% @ Outputcache duration = "1000" sqldependency = "pubs: Jobs" varybyparam = "NONE" %>
Or use
<Asp: sqldatasource id = "sqldatasource1" runat = "server" Enablecaching = "true" sqlcachedependency = "pubs: jobs "
Connectionstring = "<% $ connectionstrings: pubsconnectionstring %>"
Selectcommand = "select [job_id], [job_desc], [min_lvl], [max_lvl] from [jobs]">
</ASP: sqldatasource>