Cache(Query Notification)
am 17.01.2008 10:56:01 von raviHi,
We are planning to use SqlCacheDepency in our application(ASP.Net2.0/SQL
Server 2005).I was just doing a POC and found the Cache addition and
invalidation is behaving abnormally. I just wanted to know where its going
wrong.
I have a command object as dependency. The stored proc. returns result set
based on filter param. Basically its simple select
dbo.
above dependency cmd I can see the Cache object is still empty but a
notification entry in SQL 2005(select * from sys.dm_qn_subscriptions). But
sometimes there is an entry in ASP cache object but no notification entry in
SQL 2005. Why is it behaving strangely? I have re-produced this after
restarting IIS and clearing sql of all notifications.
Can some one help me on this?
sample code:
bool blnDepend =
System.Data.SqlClient.SqlDependency.Start("uid=<>;pwd=<>;data
source=(local);initial catalog=<>;");
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "dbo.GetAllTasks";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@TNAME", SqlDbType.NChar, 10);
cmd.Parameters["@TNAME"].Value = "T1";
cmd.Prepare();
System.Web.Caching.CacheDependency sqldependency = new
System.Web.Caching.SqlCacheDependency(cmd);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
object o = HttpContext.Current.Cache.Add("T1", "hello",
sqldependency, System.Web.Caching.Cache.NoAbsoluteExpiration,
System.Web.Caching.Cache.NoSlidingExpiration,
System.Web.Caching.CacheItemPriority.Normal, null);