打开 “VisualStudio命令提示符”
输入:aspnet_regsql.exe-S SqlServer服务器 -E -ed -d 数据库名称 -et -t 表名
注意如果使用的数据库验证方式是“SQLServer身份验证”,则需要使用如下的启动命令:
aspnet_regsql.exe -S SqlServer服务器 -U <Username> -P <Password> -ed-d数据库名称 -et -t表名
(PS:请注意大小写,把-et改成-dt可以解除缓存)
如果执行成功,会出现以下图:
以下命令可以列出改数据库开启了缓存的列表
aspnet_regsql.exe -S SqlServer服务器 -U <Username> -P <Password> -ed-d数据库名称 –lt
如果执行成功,会出现以下图:
在web.Config中配置数据连接字符串同时也要还要添加数据库缓存依赖的配置,代码如下:
<configuration>
<system.web>
<compilationdebug="true"targetFramework="4.0" />
<caching>
<sqlCacheDependencyenabled="true"pollTime="1000">
<databases>
<addname="要连接的数据库"connectionStringName="Config"pollTime="1000"/>
</databases>
</sqlCacheDependency>
</caching>
</system.web>
<connectionStrings>
<addname="Config"connectionString="Data Source=.;Initial Catalog=要连接的数据库;Persist Security Info=True;UserID=sa;Password=sa"
providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>