473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Can't get SqlCacheDependency working correctly

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
immediately.

I'm using Cache.Insert(prodName, productObject, prodDepenancy) to put
stuff into the cache, and when I go to refresh the page Cache[prodName] has
reverted to null.

Any ideas?
Feb 8 '06 #1
5 2839
Hi Joel,

Currently we are looking for some people to help you on this issue, we will
update you ASAP. Thanks for your understanding

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Feb 8 '06 #2
Hi Joel,

Welcome to the MSDN newsgroup.

As for the SQL Cache dependency in ASP.NET 2.0, we need to make sure the
configuration in the following places are correct:

1. In sqlserver, we need to make sure we've enabled the sql cache through
aspnet_regsql.exe tool

2. In ASP.NET web application, ensure that web.config file contains the
correct setting for that certain sql cache database/table

If the above are all correctly configured, there may have something else
cause the problem. And for general throubleshooting, you can try the
following means also:

a.Use Sql Profiler to monitor the SQL Server database server to see whether
there're sql query operations peformed by asp.net sql cache thread...

b.Add a RemoveCallBack handler for the cached item to see whether it is
called immediately after you add the cache item.
In addition, here is the walkthrough article in MSDN on using sql cache
dependency in asp.net 2.0, you can also try testing through this to see
whether it can work:

#Walkthrough: Using ASP.NET Output Caching with SQL Server
http://msdn2.microsoft.com/en-us/lib.../e3w8402y.aspx

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Feb 9 '06 #3
Steven,

It was my understanding that you step 1 and 2 were only needed if you
were hooking to a Sql 2000 server and Sql 2005. In order to get mine
working all I needed to do was have a user with the right permissions
() and then make sure he was hooked to a custom schema and not the dbo
schema. Also, I am sure you probably have this, otherwise it would be
giving you an error, but make sure to call SqlDependency.Start.

void Application_Start(object sender, EventArgs e)
{
SqlDependency.Start(WebConfigurationManager.Connec tionStrings["MainDB"].ConnectionString);
}

Here is my code that works for me. Note that I have my application
abstracted to multiple layers.
Data Layer:
public DataReader GetLists(Guid ownerid, ref SqlCacheDependency
scd)
{
//Note that _Command and _Connection are already declared as
new SqlCommand and SqlConnection objects respectively by this point.
_Command.Parameters.Add(new SqlParameter("@OwnerID",
SqlDbType.UniqueIdentifier, 0));
_Command.Parameters["@OwnerID"].Value = ownerid;

spname = "[dbo].[usp_ListGetList]";
_Command.Connection = _Connection;
_Command.CommandType = CommandType.StoredProcedure;
_Command.CommandText = spname;

scd = new SqlCacheDependency(_Command);
return new DataReader(_Command.ExecuteReader());

}
Here is my Business Layer
public Dictionary<string, string> LoadDictionary()
{
Dictionary<string, string> dict = new Dictionary<string,
string>();

Cache cache = HttpRuntime.Cache;
string cacheKey = "List::" + _OwnerID.ToString();
if (cache[cacheKey] == null)
{
dict.Add("", "Choose One...");

//Note that SqlBuilder is a custom wrapper class that
contains all db calls like the one shown above
using (SqlBuilder builder = new SqlBuilder())
{
SqlCacheDependency scd = null;
using (DataReader reader =
builder.GetLists(_OwnerID, ref scd))
{
while (reader.Read())
{

dict.Add(reader.GetGuid("ItemListID").ToString(),
reader.GetString("Description"));
}
}
//insert this into cache with a sql cache
dependency.
cache.Insert(cacheKey, dict, scd);
}

}
else
dict = cache[cacheKey] as Dictionary<string, string>;

return dict;
}

This took me a little while to get working, but I was having
permissions issues and not the issue you were having. But anyway I
hope this help because once you get this working it is very slick.

Chris

Feb 9 '06 #4
Any ideas yet?

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.com> wrote in message
news:GC*************@TK2MSFTNGXA01.phx.gbl...
Hi Joel,

Currently we are looking for some people to help you on this issue, we
will
update you ASAP. Thanks for your understanding

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Feb 14 '06 #5
Hi Joel,

Have you also viewed Chris and mine response in this thread?

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Feb 15 '06 #6

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

Similar topics

1
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...
1
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...
2
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...
0
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
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...
2
by: Smokey Grindle | last post by:
didnt know if this went in ado.net or ASP.net, so had to cross post... I have a ASP.NET site running on my "web" server named "web" and its running a site that has a SqlCacheDependency on it and...
4
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
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.