473,624 Members | 2,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SqlCacheDepende ncy immediately gets DependencyChang ed

3 New Member
Hi

I set up a sql cache dependency, but always receive a "DependencyChan ged" notification straight away (through CacheItemRemove d callback). Modifying the procedure didn't help me.
It used to work running on a SQL 2000 database with a SqlDataSource and a few things set in the configuration file.
The current setup is using SQL 2005 Express and caching in the datalayer/business objects.

Running profiler, I notice events ran by the SqlQueryNotific ationService :

exec sp_executesql N'BEGIN CONVERSATION TIMER (''f31d830f-fc01-dc11-9742-00166f698a50'') TIMEOUT = 120; WAITFOR(RECEIVE TOP (1) message_type_na me, conversation_ha ndle, cast(message_bo dy AS XML) as message_body from [SqlQueryNotific ationService-103f7ce3-56c0-4c67-affb-bb320ed5687a]), TIMEOUT @p2;',N'@p2 int',@p2=60000

exec dbo.p_b2ex_get_ workbooks

exec sp_executesql N'END CONVERSATION @p1; BEGIN CONVERSATION TIMER (''f31d830f-fc01-dc11-9742-00166f698a50'') TIMEOUT = 120; WAITFOR(RECEIVE TOP (1) message_type_na me, conversation_ha ndle, cast(message_bo dy AS XML) as message_body from [SqlQueryNotific ationService-103f7ce3-56c0-4c67-affb-bb320ed5687a]), TIMEOUT @p2;',N'@p2 int,@p1 uniqueidentifie r',@p2=60000,@p 1='F91D830F-FC01-DC11-9742-00166F698A50'


Any ideas about what's wrong or missing ?

Many thanks
Reinout

Code :

Global.asax :

void Application_Sta rt(object sender, EventArgs e)
{
// Code that runs on application startup
System.Data.Sql Client.SqlDepen dency.Start(Con figurationManag er.ConnectionSt rings["B2exDataba se"].ToString());
}

void Application_End (object sender, EventArgs e)
{
// Code that runs on application shutdown
System.Data.Sql Client.SqlDepen dency.Stop(Conf igurationManage r.ConnectionStr ings["B2exDataba se"].ToString());
}

Business Object :

private void DataPortal_Fetc h(FilterCriteri a criteria)
{
RaiseListChange dEvents = false;
IsReadOnly = false;

WorkbookList wbList;

Cache cache = HttpRuntime.Cac he;
wbList = cache["Workbooks"] as WorkbookList;

if (wbList == null)
{
SqlCacheDepende ncy scd = null;

using (DataTable dt = B2exDAL.Instanc e.GetWorkbooks( ref scd))
{
DataTableReader dtr = dt.CreateDataRe ader();
SafeDataReader sdr = new SafeDataReader( dtr);

while (sdr.Read())
{
this.Add(Workbo okInfo.GetWorkb ook(sdr));
}
}

wbList = this;

cache.Insert("W orkbooks", wbList, scd, Cache.NoAbsolut eExpiration, new TimeSpan(0, 20, 0),
CacheItemPriori ty.NotRemovable , new System.Web.Cach ing.CacheItemRe movedCallback(T est));
}

IsReadOnly = true;
RaiseListChange dEvents = true;
}

private void Test(string text, object sender, System.Web.Cach ing.CacheItemRe movedReason reason)
{
// Notify deletion from cache
}

DAL :

public override DataTable GetWorkbooks(re f System.Web.Cach ing.SqlCacheDep endency scd)
{
DataTable workbooks = new DataTable();

using (SqlConnection conn = new SqlConnection(b ase.ConnectionS tring))
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Sto redProcedure;
cmd.CommandText = PROC_GET_WORKBO OKS;

scd = new SqlCacheDepende ncy(cmd);

SqlDataAdapter adapter = new SqlDataAdapter( );
adapter.SelectC ommand = cmd;

adapter.Fill(wo rkbooks);
}

return workbooks;
}
May 14 '07 #1
4 5831
kenobewan
4,871 Recognized Expert Specialist
Here is an article that may help:
SQL Express Dependency Caching
May 14 '07 #2
Reinout
3 New Member
Apparantly I did nothing wrong in the code.

Since I was becoming kinda desperate, I changed my procedure to a hardcoded select statement without any other code. All of a sudden, it worked.
I found out that left joins are not allowed when using the notification service.

At the moment, I don't see another way than creating a custom query giving me an indication for changed records in one of the tables, and at that time invalidate the BO.
At least it seems to be better than polling the DB manually every few seconds.

Other workarounds are still welcome though !
May 14 '07 #3
Reinout
3 New Member
Updated DAL code :


public override DataTable GetWorkbooks(re f System.Web.Cach ing.SqlCacheDep endency scd)
{
DataTable workbooks = new DataTable();

using (SqlConnection conn = new SqlConnection(b ase.ConnectionS tring))
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Sto redProcedure;
cmd.CommandText = PROC_GET_WORKBO OKS;

SqlCommand cmdDependency = new SqlCommand("SEL ECT <field> FROM <table>", conn);
scd = new SqlCacheDepende ncy(cmdDependen cy);

SqlDataAdapter adapter = new SqlDataAdapter( );
adapter.SelectC ommand = cmd;

adapter.Fill(wo rkbooks);
}

return workbooks;
}
May 14 '07 #4
zumonth
1 New Member
I had the same issue with a stored proc before, and after spending a few hours, I tried something that made it work.

Initially I was setting the command text to the name of the stored procedure, say, "GET_PUBLISHERS ", and I used to get the notification immediately, causing my cache to get flushed. Then I added "dbo." in front of the stored proc name, like so: "dbo.GET_PUBLIS HERS", and voila, it started to work!
Oct 4 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2853
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 caching section. So, in my code I add an item to the cache with an sqlCacheDependency, referencing the named sqlCacheDependency in the web.config and the database table it is to be based on (have enabled notificiations for that table). Fine. ...
5
2432
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 caching section. So, in my code I add an item to the cache with an sqlCacheDependency, referencing the named sqlCacheDependency in the web.config and the database table it is to be based on (have enabled notificiations for that table). Fine. ...
5
2856
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 connection string has subscripe notifications permission set to grant. But now it seems that the cache is kicking my product out of the cache
2
2065
by: chris | last post by:
Hello all, Background: Using .NET 2.0, Sql Server 2005, SqlCacheDependency is utilized successfully against SqlCommand objects elsewhere in the code (in other words I have successful instances of using SqlCacheDependency). ASP.NET website built in 3 separate tiers: Presentation, Business Logic Layer (BLL), and Data Access Layer (DAL). I have a strongly typed data set that is utilized by my BLL and returns
0
1436
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 it out and got succeeded , now I just want to know whether is there any possibility to update the cache once I change the database , say: I have inserted the data's ( which is from database to dataset) into the cache for the first time and now...
10
4563
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 ID="odsAccounts" runat="server" ... EnableCaching="true" SqlCacheDependency="CommandNotification"> .... </asp:ObjectDataSource>
2
2085
by: mrashidsaleem | last post by:
Using the SQL 2005 "query notification" caching mechanism, I am caching three columns (UserId, UserName, Password) of a table called UserInfo in my web application cache. However, the cache gets invalidated (and needs to be re-loaded) when another column LastUpdateDateTime of the same table gets modified. This is NOT as per my expectation. Following is what MSDN says about Query Notifications in SQL2005...
1
3584
by: mark4asp | last post by:
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
1
2092
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 connectionstring and dbo.USStates is the table
0
8251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8688
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8352
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6115
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2614
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1800
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.