4

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 ?

2
  • You are using Sql Server correct? Commented Jul 5, 2010 at 11:27
  • What version of SQL Server are you using? The answer can be different for different versions. Commented Jul 5, 2010 at 11:39

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

FYI: This Answer applies to the old polling method. The newer notification feature of SQL Server 2005 is setup vary differently.
2

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);

2 Comments

how to add dependency for a table having a space in its name
thanx PhilPursglove i have tried [], '', but none of them worked thanx a lot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.