HighTechTalks DotNet Forums  

ASP.NET caching with SQL Server doesn't work. Help needed.

ASP.net Caching microsoft.public.dotnet.framework.aspnet.caching


Discuss ASP.NET caching with SQL Server doesn't work. Help needed. in the ASP.net Caching forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Toni
 
Posts: n/a

Default ASP.NET caching with SQL Server doesn't work. Help needed. - 08-27-2007 , 08:35 AM






Hello! I'm trying to get caching work with ASP.NET 2.0 and SQL Server
Express Edition 2005, but I have a problem and I can't figure out what I'm
doing wrong.

I have tried to do everything according to the instructions. I have enabled
the database for cache notification by running the aspnet_regsql tool on the
command line like this:
aspnet_regsql -S server -E -d database -et

Then I have run the aspnet_regsql tool to enable each table in the database
for cache notification:
aspnet_regsql -S server -E -d database -et -t tablename

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

<connectionStrings>
<add name="ConnectionString1" connectionString="Data
Source=servername;Database=databasename;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<caching>
<sqlCacheDependency enabled="true" pollTime="2000">
<databases>
<add connectionStringName="ConnectionString1"
name="KJ"/>
</databases>
</sqlCacheDependency>
</caching>

I have added this into global.asax file for the application start event:
System.Data.SqlClient.SqlDependency.Start(Configur ationManager.ConnectionStrings("ConnectionString1" ).ToString())

To test caching I wrote this piece of code where I get data from the table
MAAKUNNAT in the
database.
----------
SqlCacheDependencyAdmin.EnableTableForNotification s(ConfigurationManager.ConnectionStrings("Connecti onString1").ToString(),
"MAAKUNNAT")
Dim maakunnatDS As New DataSet

If Cache.Get("maakunnat") Is Nothing Then
Dim myConnection As New
SqlConnection(ConfigurationManager.ConnectionStrin gs("ConnectionString1").ToString())
myConnection.Open()

Dim cmd As New SqlCommand("haemaakunnat", myConnection)
cmd.CommandType = CommandType.StoredProcedure
Dim riippuvuus As New SqlCacheDependency("KJ", "MAAKUNNAT")
Dim aggDep As New AggregateCacheDependency
aggDep.Add(riippuvuus)

Dim maakunnatDA As SqlDataAdapter = New SqlDataAdapter
maakunnatDA.SelectCommand = cmd

maakunnatDA.Fill(maakunnatDS, "MAAKUNTA")
myConnection.Close()
Cache.Insert("maakunnat", maakunnatDS, aggDep)

Else
Response.Write("The data is in the cache")
maakunnatDS = Cache.Get("maakunnat")
End If
-----------------
But when I run the page I get this error.
------------------------------------------

The 'MAAKUNNAT' 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.EnableTableForNotification s 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.GetTablesEnabledForNotif ications method, or the
command line tool aspnet_regsql.exe.
----------------------------------------------
When I run the aspnet_regsql tool with the -lt parameter to get a list of
enabled tables in the database they are all enabled. I have searched many
pages in the internet and I cannot find out what I'm still doing wrong. I'd
appreciate it very much if someone could help me with this problem.

Toni S.



Reply With Quote
  #2  
Old   
Teemu Keiski
 
Posts: n/a

Default Re: ASP.NET caching with SQL Server doesn't work. Help needed. - 09-01-2007 , 12:01 PM






Hello,

have you enabled service broker in your database?

ALTER DATABASE yourdbname SET ENABLE_BROKER;

Jep, elikkä service broker pitää olla myös päällä. Oletuksena se ei ole.


--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net




"Toni" <nobody (AT) hotmail555 (DOT) com> wrote

Quote:
Hello! I'm trying to get caching work with ASP.NET 2.0 and SQL Server
Express Edition 2005, but I have a problem and I can't figure out what I'm
doing wrong.

I have tried to do everything according to the instructions. I have
enabled the database for cache notification by running the aspnet_regsql
tool on the command line like this:
aspnet_regsql -S server -E -d database -et

Then I have run the aspnet_regsql tool to enable each table in the
database for cache notification:
aspnet_regsql -S server -E -d database -et -t tablename

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

connectionStrings
add name="ConnectionString1" connectionString="Data
Source=servername;Database=databasename;Integrated Security=True"
providerName="System.Data.SqlClient"/
/connectionStrings
system.web
caching
sqlCacheDependency enabled="true" pollTime="2000"
databases
add connectionStringName="ConnectionString1"
name="KJ"/
/databases
/sqlCacheDependency
/caching

I have added this into global.asax file for the application start event:

System.Data.SqlClient.SqlDependency.Start(Configur ationManager.ConnectionStrings("ConnectionString1" ).ToString())

To test caching I wrote this piece of code where I get data from the table
MAAKUNNAT in the
database.
----------
SqlCacheDependencyAdmin.EnableTableForNotification s(ConfigurationManager.ConnectionStrings("Connecti onString1").ToString(),
"MAAKUNNAT")
Dim maakunnatDS As New DataSet

If Cache.Get("maakunnat") Is Nothing Then
Dim myConnection As New
SqlConnection(ConfigurationManager.ConnectionStrin gs("ConnectionString1").ToString())
myConnection.Open()

Dim cmd As New SqlCommand("haemaakunnat", myConnection)
cmd.CommandType = CommandType.StoredProcedure
Dim riippuvuus As New SqlCacheDependency("KJ", "MAAKUNNAT")
Dim aggDep As New AggregateCacheDependency
aggDep.Add(riippuvuus)

Dim maakunnatDA As SqlDataAdapter = New SqlDataAdapter
maakunnatDA.SelectCommand = cmd

maakunnatDA.Fill(maakunnatDS, "MAAKUNTA")
myConnection.Close()
Cache.Insert("maakunnat", maakunnatDS, aggDep)

Else
Response.Write("The data is in the cache")
maakunnatDS = Cache.Get("maakunnat")
End If
-----------------
But when I run the page I get this error.
------------------------------------------

The 'MAAKUNNAT' 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.EnableTableForNotification s 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.GetTablesEnabledForNotif ications method, or the
command line tool aspnet_regsql.exe.
----------------------------------------------
When I run the aspnet_regsql tool with the -lt parameter to get a list of
enabled tables in the database they are all enabled. I have searched many
pages in the internet and I cannot find out what I'm still doing wrong.
I'd appreciate it very much if someone could help me with this problem.

Toni S.




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.