我如何使用Web.Config中对我的连接字符串变换? [英] How do I use Web.Config transform on my connection strings?

查看:81
本文介绍了我如何使用Web.Config中对我的连接字符串变换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我当前的项目,我有一些连接字符串的有效期为本地开发机器:

In my current project, I have some connection strings that are valid for local development machines:

<configuration>
  <connectionStrings>
    <add name="ApplicationServices"
         connectionString="Data Source=localhost;Initial Catalog=MyDB;Integrated Security=SSPI"
  </connectionStrings>
....
</configuration>

我将如何使用的Web.Config转变,从这个前pression转换成另外一种是我们的生产服务器?在生产服务器一会是这个样子:

How would I use the Web.Config transforms to convert from this expression to one valid for our production server? The production server one would look something like:

<configuration>
  <connectionStrings>
    <add name="ApplicationServices"
         connectionString="Data Source=IPAddress,Port;Initial Catalog=SomeOtherDB;User ID=TopSecretUsername;Password=SecurePassword"
  </connectionStrings>
....
</configuration>

的语法并不明显给我,我完全在所著的Grokking的的就可以了页面

推荐答案

这对我的作品,但我也发现它是在时间有点古怪。
您将需要创建一个名为Web.Config.Release另一个文件并用以下填充:

This works for me but I too have found it to be a bit flakey at times. You will need to create another file called Web.Config.Release and fill it with the following:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

  <connectionStrings>
    <add name="local" connectionString="Data Source=IPAddress,Port;Initial Catalog=SomeOtherDB;User ID=TopSecretUsername;Password=SecurePassword" 
    xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
  </connectionStrings>

  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />

  </system.web>
    <appSettings>
        <add key="default_db_connection" value="local" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
    </appSettings>
</configuration>

这篇关于我如何使用Web.Config中对我的连接字符串变换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆