473,498 Members | 1,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQLCacheDependency not working - Cache item is always null

Help: SQLCacheDependency not working. When I step through my code
with the debugger I notice that the condition below:

(cacheItem == null)

is always true.

I have setup SQLCacheDependency to work with 11 tables in the
database. When I update the database without actually changing the
"PensionFund" table then I notice that the Cache is being invalidated
anyway. This is not the behavior I want. I only want the Cache to be
invalidated when I alter the PensionFund table.

data_list class:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Caching;
using System.Web.Security;
using System.Data.SqlClient;
using System.Text;
using System.Collections.Generic;

public class data_list
{
public static List<PensionFundGetPensionFunds(out bool changed)
{
changed = false;
string cacheName = "PensionFund";
List<PensionFundcacheItem = HttpRuntime.Cache[cacheName] as
List<PensionFund>;
if (cacheItem == null)
{
changed = true;
cacheItem = GetPensionFunds_FromDataSource();
SqlCacheDependency dep = new SqlCacheDependency("Admin",
cacheName);
HttpRuntime.Cache.Insert(cacheName, cacheItem, dep);
}
return cacheItem;
}

private static List<PensionFundGetPensionFunds_FromDataSource()
{
List<PensionFundpensionFunds = new List<PensionFund>();
using (SqlConnection dConn = new
SqlConnection(data_connection.SqlConnectionString) )
{
using (SqlCommand cmd = new
SqlCommand("PensionFund_Get_All_For_Listing", dConn))
{
cmd.CommandType = CommandType.StoredProcedure;
try
{
dConn.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
PensionFund pensionFund = new PensionFund
(
(int)reader["PensionFundID"],
reader["FundName"].ToString()
);
pensionFunds.Add(pensionFund);
}
}
}
catch (Exception e)
{ pensionFunds = null; }
}
}
return pensionFunds;
}
}
web.config entries:

<connectionStrings>
<add name="myDBConnString_localdev" connectionString="Data Source=.
\SQLEXPRESS;Integrated Security=True;Initial Catalog=myDB_40;Min Pool
Size=5;" providerName="System.Data.SqlClient"/>
</connectionStrings>

<system.web>
<caching>
<sqlCacheDependency enabled="true" pollTime="1000">
<databases>
<add name="Admin"
connectionStringName="myDBConnString_localdev" pollTime="1000" />
</databases>
</sqlCacheDependency>
</caching>
</system.web>

Aug 7 '07 #1
1 3570
OK, My fault. Sorry for bothering y'all. I noticed that although the
content of data in the PensionFund table is NOT altered it is actually
changed each time because the PensionFund table is either INSERTed
into or UPDATEd. Hence the SQLCacheDependency is rightly flagging a
change. Ideally I need to record whether the PensionFund table data
changes so that, then and only then will I need to UPDATE it.

On 7 Aug, 15:49, mark4asp <mark4...@gmail.comwrote:
Help: SQLCacheDependency not working.
Aug 7 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2838
by: stewart | last post by:
I've got the standard SqlCacheDependency working just fine , ie. I've defined (and encrypted) the connectionStrings section in the web.config, and I've also defined an an sqlCacheDependency in the...
5
2418
by: Adrian Parker | last post by:
I've got the standard SqlCacheDependency working just fine , ie. I've defined (and encrypted) the connectionStrings section in the web.config, and I've also defined an an sqlCacheDependency in the...
5
2843
by: Joel Barsotti | last post by:
I'm trying to get sql cache dependency working correctly. I've got sql server 2005 for my back end. I've don the "ALTER DATABASE dbName SET broker_enable" command. I made sure the user in my...
1
1691
by: Yosi | last post by:
Hi, I have a wierd problem about the SqlCacheDependency class. It just works for a couple of minutes. After 2 minutes or more, the cache does not expire anymore. I'm using SQL Server 2005 as...
0
1426
by: Jayender | last post by:
I read an article : MSDN help topic. This will get you on the right track. http://msdn2.microsoft.com/en-us/library/system.web.caching.sqlcachedependency.aspx and its really amazing .. I tried...
10
4542
by: J055 | last post by:
Hi I've been trying out SqlCacheDependency using the ObjectDataSource and SQL Server 2005. It all works quite well with the minimum of configuration, e.g. <asp:ObjectDataSource...
4
5820
by: Reinout | last post by:
Hi I set up a sql cache dependency, but always receive a "DependencyChanged" notification straight away (through CacheItemRemoved callback). Modifying the procedure didn't help me. It used to...
1
2082
by: | last post by:
Hey Guys, I have been struggling with this for few days. when i use SqlCacheDependency sqlDependency=new SqlCacheDependency("test","dbo.USStates"); where test is the name of...
7
1526
by: Adrian | last post by:
Hi, I'm trying to add caching to our asp app, but am having problems with the SQLCacheDependancy not invalidating the cache when the table changes. Using vs2008, sqlserver 2005 developer edition....
0
7004
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7167
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7208
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5464
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.