C # Database Cache dependency

Source: Internet
Author: User

1. Start the notification database for cache dependencies

Run in the VS Developer command prompt (switch to the directory where Aspnet_regsql.exe is located, sample directory: C:\Windows\Microsoft.NET\Framework64\v4.0.30319):

aspnet_regsql-s. -u sa-p pwd-ed-d xxx-et-t xxx;

Cache dependency Disabled:

Aspnet_regsql-s. \DS-E-dd-d XXX

-s server name-E Integrated Authentication-u account-p password-ed CREATE database for SQL cache dependency-dd disable-D database name-et start table for SQL Cache-T table name

2. Configuring the Web. config file

Add under system.web

   <caching>        <sqlcachedependency enabled= "true" >          <databases>            <add name= "Practicedb "Connectionstringname=" constring "polltime="/>           </databases>        </sqlCacheDependency>      </caching>

Then add the corresponding key value under the configuration

  

 

3. Inserting a cache with database dependencies

if (cache["key"] = = null)            {                Nmdb. Dataclassesdatacontext db = new Nmdb. Dataclassesdatacontext ();                var r = (from res in DB.T1 select res). ToList ();                Cache.Insert ("Key", R, New SqlCacheDependency ("Practicedb", "student"));            Repeater1.datasource = cache["key"];            Repeater1.databind ();

Done. The cache is accessed directly every time the database has not changed, which can be confirmed in SQL Server Profiler. It's only when you change the data in the database that you request the database again to get the data.

C # Database Cache dependency

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.