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 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 SqlQueryNotificationService :
exec sp_executesql N'BEGIN CONVERSATION TIMER (''f31d830f-fc01-dc11-9742-00166f698a50'') TIMEOUT = 120; WAITFOR(RECEIVE TOP (1) message_type_name, conversation_handle, cast(message_body AS XML) as message_body from [SqlQueryNotificationService-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_name, conversation_handle, cast(message_body AS XML) as message_body from [SqlQueryNotificationService-103f7ce3-56c0-4c67-affb-bb320ed5687a]), TIMEOUT @p2;',N'@p2 int,@p1 uniqueidentifier',@p2=60000,@p1='F91D830F-FC01-DC11-9742-00166F698A50'
Any ideas about what's wrong or missing ?
Many thanks
Reinout
Code :
Global.asax :
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
System.Data.SqlClient.SqlDependency.Start(Configur ationManager.ConnectionStrings["B2exDatabase"].ToString());
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
System.Data.SqlClient.SqlDependency.Stop(Configura tionManager.ConnectionStrings["B2exDatabase"].ToString());
}
Business Object :
private void DataPortal_Fetch(FilterCriteria criteria)
{
RaiseListChangedEvents = false;
IsReadOnly = false;
WorkbookList wbList;
Cache cache = HttpRuntime.Cache;
wbList = cache["Workbooks"] as WorkbookList;
if (wbList == null)
{
SqlCacheDependency scd = null;
using (DataTable dt = B2exDAL.Instance.GetWorkbooks(ref scd))
{
DataTableReader dtr = dt.CreateDataReader();
SafeDataReader sdr = new SafeDataReader(dtr);
while (sdr.Read())
{
this.Add(WorkbookInfo.GetWorkbook(sdr));
}
}
wbList = this;
cache.Insert("Workbooks", wbList, scd, Cache.NoAbsoluteExpiration, new TimeSpan(0, 20, 0),
CacheItemPriority.NotRemovable, new System.Web.Caching.CacheItemRemovedCallback(Test)) ;
}
IsReadOnly = true;
RaiseListChangedEvents = true;
}
private void Test(string text, object sender, System.Web.Caching.CacheItemRemovedReason reason)
{
// Notify deletion from cache
}
DAL :
public override DataTable GetWorkbooks(ref System.Web.Caching.SqlCacheDependency scd)
{
DataTable workbooks = new DataTable();
using (SqlConnection conn = new SqlConnection(base.ConnectionString))
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = PROC_GET_WORKBOOKS;
scd = new SqlCacheDependency(cmd);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = cmd;
adapter.Fill(workbooks);
}
return workbooks;
}
4 5823
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 !
Updated DAL code :
public override DataTable GetWorkbooks(ref System.Web.Caching.SqlCacheDependency scd)
{
DataTable workbooks = new DataTable();
using (SqlConnection conn = new SqlConnection(base.ConnectionString))
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = PROC_GET_WORKBOOKS;
SqlCommand cmdDependency = new SqlCommand("SELECT <field> FROM <table>", conn);
scd = new SqlCacheDependency(cmdDependency);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = cmd;
adapter.Fill(workbooks);
}
return workbooks;
}
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_PUBLISHERS", and voila, it started to work!
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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
|
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).
...
|
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...
| |
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>
|
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....
|
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...
|
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
|
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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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. ...
|
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...
|
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...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |