Groups | Blog | Home
all groups > sql server programming > august 2007 >

sql server programming : ASP.NET caching with SQL Server doesn't work, what am I doing wrong?



Toni
8/11/2007 5:51:17 PM
Hello! I'm trying to use ASP.NET caching with my web site and SQL Server,
but I have a problem.

First I run the following command on the command line succesfully to enable
the database for cache notification.
aspnet_regsql -S [SERVER] -E -d [database] -ed

Then I run the following command on the command line succesfully for each
table in the database.
aspnet_regsql -S [SERVER] -E -d [database] -et -t [table]

I added the necessary parts into the web.config file, so that it is like
this

<connectionStrings>
<add name="ConnectionString1"
connectionString="Server=servername;Database=databasename;Trusted_Connection=yes"
/>
</connectionStrings>

<caching>
<sqlCacheDependency enabled="true" pollTime="2000">
<databases>
<add connectionStringName="ConnectionString1"
name="KJ"/>

</databases>
</sqlCacheDependency>
</caching>

Then I added the following line into the beginning of default.aspx
<%@ OutputCache Duration="86400" VaryByParam="*"
SqlDependency="KJ:ILMOITUKSET" %>

But when I run the page it gives the following error:
-----------------------------
The 'ILMOITUKSET' table in the database 'KJ' is not enabled for SQL cache
notification.

Please make sure the table exists, and the table name used for cache
dependency matches exactly the table name used in cache notification
registration.

To enable a table for SQL cache notification, please use
SqlCacheDependencyAdmin.EnableTableForNotifications method, or the command
line tool aspnet_regsql. To use the tool, please run 'aspnet_regsql.exe -?'
for more information.

To get a list of enabled tables in the database, please use
SqlCacheDependencyManager.GetTablesEnabledForNotifications method, or the
command line tool aspnet_regsql.exe.
-----------------------------------
I run the aspnet_regsql.exe with the -lt parameter to see the list of files
that are enabled for cache notification and they are all enabled. Could
someone help me with this problem and tell me what I'm doing wrong? Thank
you so much in advance.

Toni

mark4asp
8/14/2007 6:38:06 AM
Hi Toni, perhaps you should take a step back and just get the
data-caching working first?

Have you included the necessary line(s) in Global Application_OnStart()?

System.Data.SqlClient.SqlDependency.Start(ConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString);
see:
<http://blogs.msdn.com/tolong/archive/2007/02/16/sql-cache-dependency.aspx>
(Perhaps there may be more entries required than that - I can't tell
right now as all my code is at work and I'm here at home). I try to post
again in a couple of hours when I get into work.

I think the error message is a bit ambiguous since the term "KJ" is the
name of the cache dependency for that database - not necessarily the
same as the name of your actual SQL database.

Sorry I can't answer your problem precisely as I have only implemented
data caching and I don't use that page directive.

On Sat, 11 Aug 2007 17:51:17 +0300, "Toni" <nobody@hotmail555.com>
[quoted text, click to view]
AddThis Social Bookmark Button