Database cache mechanism Configuration
After reading the webcast of Boss su Peng, we talked about setting cache for SQL.
Step 1: Enable the database for the SQL cache dependency.
The visual studio2005 command prompt is displayed ,.
Enter as shown in. And enter
Aspnet_regsql.exe-s (local)-E-ed-D northwind-et-T employee
Here-S is your SQL Server
-E Indicates integration window verification.
-Et: Configure SQL cache Dependencies
-D: the database to be cached.-T: the cache table.
And so on.
You can use aspnet_regsql.exe -? View.
After Successful Configuration
The following table (aspnet_sqlcachetablesforchangenotification) is displayed in northwind.
The following stored procedures exist:
After the preceding configuration.
Step 2. Create a web site
Create a web site. Enter the following in Web. config:
<? XML version = "1.0" encoding = "UTF-8"?>
<! --
Note: In addition to manually editing this file, you can also use
Web management tools to configure application settings. You can use
"Website"-> "ASP. NET configuration" option.
The complete list of settings and comments is displayed in
In machine. config. Comments, this file is usually located in
\ Windows \ Microsoft. NET \ framework \ v2.x \ config
-->
<Configuration>
<Connectionstrings>
<Add name = "conn" connectionstring = "Server =.; database = northwind; uid = sa; Pwd =''; "providername =" system. Data. sqlclient "/>
</Connectionstrings>
<System. Web>
<Caching>
<Sqlcachedependency enabled = "true" polltime = "1000">
<Databases>
<Add name = "northwind" connectionstringname = "conn" polltime = "1000"/>
</Databases>
</Sqlcachedependency>
</Caching>
<! --
Set compilation DEBUG = "true" to insert the debugging symbol
Compiled pages. However, this
Performance is affected, so this value is only available during development.
Set to true.
-->
<Compilation DEBUG = "false"/>
<! --
In the <authentication> section, you can configure
Security Authentication mode,
To identify the user.
-->
<Authentication mode = "Windows"/>
<! --
If an unprocessed error occurs during request execution,
You can configure the corresponding processing steps in the <mermerrors> section. Specifically,
This section allows developers to configure
HTML error page to be displayed
To replace the error stack trace.
<Customerrors mode = "remoteonly" defaultredirect = "genericerrorpage.htm">
<Error statuscode = "403" Redirect = "noaccess.htm"/>
<Error statuscode = "404" Redirect = "filenotfound.htm"/>
</Customerrors>
-->
</System. Web>
</Configuration>
On the default. aspx page, enter
<% @ Page Language = "C #" autoeventwireup = "true" maintainscrollpositiononpostback = "true" codefile = "default. aspx. cs" inherits = "default" %>
<% @ Outputcache duration = "600" sqldependency = "northwind: employees" varybyparam = "NONE" %>
<! 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> No title page </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div style = "width: 100px">
</Div>
<Asp: gridview id = "gridview1" runat = "server" autogeneratecolumns = "false" datakeynames = "employeeid" datasourceid = "sqldatasource1"
>
<Columns>
<Asp: boundfield datafield = "employeeid" headertext = "employeeid" insertvisible = "false"
Readonly = "true" sortexpression = "employeeid"/>
<Asp: boundfield datafield = "lastname" headertext = "lastname" sortexpression = "lastname"/>
<Asp: boundfield datafield = "firstname" headertext = "firstname" sortexpression = "firstname"/>
</Columns>
</ASP: gridview>
<Asp: sqldatasource id = "sqldatasource1" runat = "server" connectionstring = "<% $ connectionstrings: conn %>"
Selectcommand = "select [employeeid], [lastname], [firstname] from [employees]"> </ASP: sqldatasource>
& Nbsp; <br/>
& Nbsp; current time
<Asp: Label id = "label1" runat = "server" text = "label"> </ASP: Label>
</Form>
</Body>
</Html>
In the backend CS.
Protected void page_load (Object sender, eventargs E)
{
This. label1.text = system. datetime. Now. tostring ();
}
The work is complete. Every time we refresh, the time will not change because the page is cached.
------------------------------------------------------------------
------------------------------------------------------------------
When we modify the employees field in the database, we modify 9th records ..
------------------------------------------------------------------
------------------------------------------------------------------
Found.
Time changed... When we modify the database, it changes.
Sample download
/Files/suiqirui19872005/demo6.rar