[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.caching

.NET 2.0, SqlCacheDependancy not expiring the cache

Adam Tibi

2/20/2006 11:31:00 AM

Hello,
SqlCacheDependency sqlCacheDependency = new SqlCacheDependency("MyDBName",
"dbo.MyTableName");
HttpContext.Current.Cache.Insert("key", "value", sqlCacheDependency);

This code works as expected and expires the "key" when the table
dbo.MyTableName has any record changed.

However, in the same position, if you replace this code with this one:

SqlCommand command = new SqlCommand("SELECT SomeField FROM dbo.MyTableName",
new
SqlConnection(ConfigurationManager.ConnectionStrings["Default"].ConnectionString));
SqlCacheDependency sqlCacheDependency = new SqlCacheDependency(command);
HttpContext.Current.Cache.Insert("key", "value", sqlCacheDependency);

It doesn't work if you change any value within the "SomeField", I even tried
setting a wrong select statment to check if it is being executed but nothing
happened, also tried to replace the connection string with one that doesn't
point to a real database but nothing happened as well (do I need to open the
connection myself?)!

I assume the database is well configured and I didn't miss any configuration
because the first code worked fine for me, does any one have a clue what I
might be missing in the second code?

Thank you in advance,
Adam