有没有人知道SqlCacheDependency怎么和SQL Server2005的查询通知一起使用?
比如如下代码:
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings[ "MyDevDB "].ConnectionString);
SqlDataAdapter adapter = new SqlDataAdapter( "select FontFamilyID, FontFamilyName from dbo.FontFamily where FontFamilyID=2 ", connection);
SqlDep = new SqlCacheDependency(adapter.SelectCommand);
Cache.Insert( "FontFamily ", "value item ", SqlDep);
按道理当我修改dbo.FontFamily表中FontFamilyID=2的FontFamilyName之后, Cache[ "FontFamily "]应失效, 但它并没有失效, 有人知道为什么吗?
------解决方案--------------------我来顶
------解决方案--------------------web.config里面要加上配置
<cache>
<sqlCacheDependency enabled= "true " pollTime= "500 ">
<databases>
<add name= "database1 "
connectionStringName= "MyDevDB " />
</databases>
</sqlCacheDependency>
</cache>
在页面上的outputCache中:
<%@ outputcache duration= "5000 " varybyparam= "None " sqldependency= "database1:表名 " %>