指定要在web.config中使用活动的连接字符串 [英] Specify the active connection string to use in Web.Config
问题描述
是否有一个快速简便的方法来设置Web.Config中的连接字符串是有效的连接字符串?
我基本上要适当命名我的连接字符串,然后设置一个作为活跃,而无需切换出名称或重新编译我的应用程序。
事情是这样的:
<添加名称=当前的connectionString ={}本地/><添加名称=本地的connectionString = [...]/>
<添加名称=RemoteOnMyServer的connectionString = [...]/>
<添加名称=RemoteAzure的connectionString = [...]/>
我不认为这是可能的,你问的方式。但是,你可以将连接字符串块到一个单独的文件中,然后控制哪些文件是活动之一:
<是connectionStrings configSource =LocalDb.config/>
然后你就可以有不同的配置文件:
LocalDb.config
RemoteOnMyServer.config
RemoteAzure.config
<&等等GT;
那里将举行这样的事情每个人:
<?XML版本=1.0&GT?;
<&是connectionStrings GT;
<添加名称=namedConnectionString的connectionString =数据源= ...的providerName =.../>
< /&是connectionStrings GT;
交换台之间便成为改变 configSource
在&LT的问题;是connectionStrings />
元素。
Is there a quick and easy way to set a connection string in Web.Config to be the active connection string?
I basically want to name my connection strings appropriately and then set one as active without having to switch out the names or re-compile my application.
Something like this:
<add name="Current" connectionString="{Local}"/>
<add name="Local" connectionString=[...]" />
<add name="RemoteOnMyServer" connectionString=[...]" />
<add name="RemoteAzure" connectionString=[...]" />
I don't think that is possible the way you asked. But you can move the connection strings block to a separate file and then control which FILE is the active one:
<connectionStrings configSource="LocalDb.config"/>
Then you can have separate config files:
LocalDb.config
RemoteOnMyServer.config
RemoteAzure.config
<etc>
Each one of there would hold something like this:
<?xml version="1.0"?>
<connectionStrings>
<add name="namedConnectionString" connectionString="Data Source=..." providerName="..." />
</connectionStrings>
Swithcing between them then becomes a matter of changing the configSource
on the <connectionStrings />
element.
这篇关于指定要在web.config中使用活动的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!