http://topic.csdn.net/u/20071014/22/0cf68d82-e42f-4f1e-a433-1abfdb9d5cd1.html
我使用sql server 2005 express 来进行缓存依赖,开发环境是.net 2.0 + vista 。
不知道我是不是理解错误了,我设置一个Cache和数据库中表tb_cache关联,希望在这个表更改时会能时cache失效。但是,好像没有反映。
protected void Page_Load(object sender, EventArgs e)
{
DateTime storetime=new DateTime ();
if (Cache["storetime"] == null)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cachecon"].ConnectionString);
con.Open();
SqlCommand command = new SqlCommand("select id,sign from dbo.tb_cache where id=3",con);
SqlCacheDependency sp = new SqlCacheDependency(command);
storetime = DateTime.Now;
this.Cache.Insert("storetime", storetime,sp, DateTime.Now.AddSeconds(60), System.Web.Caching.Cache.NoSlidingExpiration,
System.Web.Caching.CacheItemPriority.High, null);
}
else
{
storetime=(DateTime)Cache["storetime"];
}
lit_time.Text = "storetime:"+storetime.ToString();
}
我在另一个页面中执行修改id=3的记录,
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cachecon"].ConnectionString);
con.Open();
SqlCommand command = new SqlCommand("update tb_cache set sign= '"+DateTime.Now.ToString ()+" ' where id=3", con);
int returnvalue=command.ExecuteNonQuery();
this.Response.Write(returnvalue.ToString());
可当我修改后,刷新原来的页面还是缓存中的内容。
global.asax中也写了
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
System.Data.SqlClient.SqlDependency.Start(ConfigurationManager.ConnectionStrings["cachecon"].ConnectionString);
}
void Application_End(object sender, EventArgs e)
{
// 在应用程序关闭时运行的代码
System.Data.SqlClient.SqlDependency.Stop(ConfigurationManager.ConnectionStrings["cachecon"].ConnectionString);
}
请问是不是我的数据库里设置的有问题,需要我开启什么,链接时我是使用的sa帐号进行数据库访问的。
通过SELECT * FROM sys.databases,查找到我用的那个库的is_broker_enabled=1,这个应该是已经开启了broker_service了吧?
我在另一个服务器上用了之后,导致global.asax出错提示那个数据库没有开启broker_service,而在我的机器上行运行时没有任何的出错提示,我想应该配置上对的了吧。
那还有什么地方有可能有问题呢?谢谢
----------
我发现执行了update语句之后,我能够在sql server 里看到队列中有一条新的:
SqlQueryNotificationService-e7a46a94-b045-47cf-b7b9-49b70679370c
在活动监视器里,状态是suspend,命令delete,等待类型 BROKER_RECEIVE_WAITFOR