【发布时间】:2010-11-22 12:22:29
【问题描述】:
我在我的 ASP.NET 应用程序中使用 sql 依赖缓存,为了实现这一点,我在 web.config 中有以下条目:
<connectionStrings>
<add name="DatabaseName" connectionString="Data Source=.\Dev;Initial Catalog=DatabaseName;Integrated Security=True" />
</connectionStrings>
<system.web>
<caching>
<sqlCacheDependency enabled="true">
<databases>
<add name="DatabaseName" connectionStringName="DatabaseName"/>
</databases>
</sqlCacheDependency>
</caching>
</system.web>
在应用程序中,使用 web.config 中指定的数据库名称创建 SqlCacheDependency,如下所示:
var tableDependency = new SqlCacheDependency("DatabaseName", "TableName");
我想要实现的是删除 web.config 中对连接字符串的需求,因为这个应用程序的连接字符串在放置到不同的服务器时可能会发生变化。
应用程序中已经有一个连接字符串类,它返回当前所在服务器的正确字符串,所以如果不使用它,我将不得不手动更改每个服务器上 web.config 中的连接字符串。
提前致谢,
格雷格。
【问题讨论】:
标签: c# asp.net web-config connection-string