更改连接字符串动态 [英] Changing connection string dynamically
问题描述
我在那里我得到动态生成的数据库的情况。我想创建为每一个数据库连接字符串。因此,只有初始目录参数将被改变。其他参数我会从网络配置文件中得到它。它已经有连接字符串的所有条目。我想动态的基础上创建的数据库只改变初始目录的一部分。
I have a scenario where i am getting dynamically generated databases. I want to create a connection string for each database. So only initial catalog parameter will be changing. Other parameters i ll get it from web config file. It is already having all entries of connection string. I want to change only initial catalog part dynamically based on database created.
请提出有没有什么办法可以轻松地做到这一点。
Please suggest is there any way to easily to do this.
推荐答案
使用的 SqlConnectionStringBuilder
。从配置文件设置并修改<一个href=\"http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnectionstringbuilder.initialcatalog.aspx\"相对=nofollow> InitialCatalog
每个数据库。
Use SqlConnectionStringBuilder
. Set it up from the config file and change the InitialCatalog
for each database.
这篇关于更改连接字符串动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!