交换连接字符串(执行类似于重命名重构的快捷方式)
Interchange Connection string (Short cut to do something similar to Rename Refactoring)
我在 Properties
中保存了两个需要互换的连接字符串。
一个用于 database
,用于测试我的应用程序,另一个用于实际 database
,该应用程序将用于该应用程序。
我的问题是我必须在不同的地方多次使用连接字符串 类,现在我正在通过复制和粘贴手动更改为连接字符串。
是否可以做类似Rename Refactoring (C#)的事情,但实际上不是重命名,而是将连接字符串替换为第二个?
也就是说,我的第一个连接字符串是这样的,
using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.ConnectionString_One))
将每个连接字符串值替换为第二个连接字符串,
using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.ConnectionString_Two))
One is for a database that is used to test my application and the
other is for the actuall database that the application will be used
on.
如果我没理解错的话,您是在尝试替换生产版本中的连接字符串。这是操作步骤。
- 在配置文件中保存连接字符串
示例代码:(web.config 或 app.config)
<connectionStrings>
<add name="ConnectionString" connectionString="{testing}" providerName="System.Data.SqlClient"/>
</connectionStrings>
创建一个构建转换(默认情况下,它将有debug
构建和release
构建
用发布版本中的生产连接字符串替换测试连接字符串
示例代码:(web.release.config 或 app.release.config)
<connectionStrings>
<add xdt:Transform="Replace" xdt:Locator="Match(name)" name="ConnectionString" connectionString="{production}" providerName="System.Data.SqlClient"/>
</connectionStrings>
希望对您有所帮助。
阅读更多信息:https://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx
我在 Properties
中保存了两个需要互换的连接字符串。
一个用于 database
,用于测试我的应用程序,另一个用于实际 database
,该应用程序将用于该应用程序。
我的问题是我必须在不同的地方多次使用连接字符串 类,现在我正在通过复制和粘贴手动更改为连接字符串。
是否可以做类似Rename Refactoring (C#)的事情,但实际上不是重命名,而是将连接字符串替换为第二个?
也就是说,我的第一个连接字符串是这样的,
using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.ConnectionString_One))
将每个连接字符串值替换为第二个连接字符串,
using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.ConnectionString_Two))
One is for a database that is used to test my application and the other is for the actuall database that the application will be used on.
如果我没理解错的话,您是在尝试替换生产版本中的连接字符串。这是操作步骤。
- 在配置文件中保存连接字符串
示例代码:(web.config 或 app.config)
<connectionStrings>
<add name="ConnectionString" connectionString="{testing}" providerName="System.Data.SqlClient"/>
</connectionStrings>
创建一个构建转换(默认情况下,它将有
debug
构建和release
构建用发布版本中的生产连接字符串替换测试连接字符串
示例代码:(web.release.config 或 app.release.config)
<connectionStrings>
<add xdt:Transform="Replace" xdt:Locator="Match(name)" name="ConnectionString" connectionString="{production}" providerName="System.Data.SqlClient"/>
</connectionStrings>
希望对您有所帮助。
阅读更多信息:https://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx