在做一个SQl缓存依赖的 例子.(电脑装的 sqlexpress. northwind 数据库也装好了)
先在 web.config 中加入<caching>
      <sqlCacheDependency enabled="true" pollTime="1000">
        <databases>
          <add connectionStringName="NorthwindConnectionString" name="Northwind" pollTime="1000"/>
        </databases>
      </sqlCacheDependency>
</caching>
和<connectionStrings>
    <remove name="NorthwindConnectionString"/>

    <add name="NorthwindConnectionString" connectionString="Data Source=.\sqlexpress;Initial Catalog=Northwind;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
然后在页面的 load 里 加入System.Web.Caching.SqlCacheDependencyAdmin.EnableTableForNotifications(System.Configuration.ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString, "Orders");结果运行时就出现错误如下The database 'Northwind' is not enabled for SQL cache notification.To enable a database for SQL cache notification, please use the System.Web.Caching.SqlCacheDependencyAdmin.EnableNotifications method, or the command line tool aspnet_regsql. To use the tool, please run 'aspnet_regsql.exe -?' for more information.
哪位遇到过同样的问题麻烦指教一下 我google了一晚上也没有结果.............跪谢了 先

解决方案 »

  1.   

    是不是用户权限的问题? 如果是的话, 我用 SQL Server Management Studio Express 给如何更改?
      

  2.   

    数据库需要执行一句话,而且需要是sqlserver2005 ,
    ALTER DATABASE test SET enable_BROKER//设置数据库开启broker模式GRANT SUBSCRIBE QUERY NOTIFICATIONS TO "HYSF12\Administrator"//设置权限
    sqlserver2000是轮询的方式缓存,不太会
      

  3.   

    sql cache dependency是必须配置数据库的。具体配置方法有点复杂。如果特别有兴趣的话可以baidu、Google一下但不推荐这种缓存方法
      

  4.   

    还是给你贴出来吧!在vs2005命令行工具中,执行aspnet_regsql.exe -E -S .\SqlExpress -d aspnetdb -ed (通知了数据库aspnetdb要进行缓存依赖 )aspnet_regsql.exe -E -S .\SqlExpress -d aspnetdb -t Customers -ed(确定了数据库中Customers表要实现缓存依赖)
      

  5.   

    关于这个楼主可以去cnblogs上搜sqlCacheDependency就可以得到很多的信息
      

  6.   

    <add name="NorthwindConnectionString" connectionString="Data Source=ARAS02-XP;Initial Catalog=Northwind;User ID=sa;Password = sa;"
       providerName="System.Data.SqlClient" />
     </connectionStrings>
           <system.web>
        <caching>
          <sqlCacheDependency enabled ="true">
            <databases>
              <add name="Northwind" connectionStringName ="NorthwindConnectionstring" pollTime ="500"/>
            </databases >
          </sqlCacheDependency >
        </caching>
    <%@ OutputCache Duration="3600" VaryByParam="None" SqlDependency="Northwind:Customers" %>aspnet_regsql.exe -E -S .\SqlExpress -d aspnetdb -ed SqlCacheDependency empDependency = new SqlCacheDependency(
    "Northwind", "");
    参考