user284291
user284291

Reputation:

How do we enable SQL cache dependency in ASP.NET 2.0?

I think there are some steps to enable SQL Cache Depdndency :

Enabling notifications, changes in web.xml and then using Cache Dependency object.

Please help how do I pass through them ?

Upvotes: 4

Views: 7133

Answers (2)

PhilPursglove
PhilPursglove

Reputation: 12589

To enable a table for SQL cache dependency use, you'll need to first run the aspnet_regsql.exe tool from a command-line prompt, with these options:

aspnet_regsql -S servername -U login -P password -ed -d databasename -et -t tablename

If your table name contains a space, then wrap the table name in quotes e.g.

aspnet_regsql -S servername -U login -P password -ed -d databasename -et -t "table name"

In your web.config, you'll need to add a caching section:

<system.web>
    <caching>
      <sqlCacheDependency enabled = "true" pollTime = "60000" >
        <databases>
          <add name="northwind" 
            connectionStringName="Northwind"
            pollTime="9000000"
          />
      </databases>
    </sqlCacheDependency>
  </caching>
</system.web>

When you add an item into your Cache, you use the SqlCacheDependency object to set up the relationship between the cached object and the underlying table:

SqlCacheDependency dependency = new SqlCacheDependency("databasename", "tablename");

Cache.Add(key, object, dependency);

Upvotes: 2

Daniel Dyson
Daniel Dyson

Reputation: 13230

Have a look at this post. It takes you through using the Aspnet_regsql.exe tool, which sets it up for you.

Here is an excerpt from the above post:

...To enable a cache dependency on a particular database, run this command:
aspnet_regsql.exe -S server -U user -P password -d database -ed

This creates a new table, AspNet_SqlCacheTablesForChangeNotification, 
in the designated database. Next, several AspNet_SqlCacheXxxx stored procs
are created in the same database.

Then look at this post from MSDN for an overview, with lots of How-to links.

Upvotes: 3

Related Questions