1

Can anyone suggest how I could programatically switch debug and live connection strings?

I've seen other people have passed an EntityConnection to the constructor from the controller like this :

private XYZDatabase db = new XYZDatabase(ConfigurationManager.
ConnectionStrings["XYZDatabase-TEST"].ConnectionString);

but it still requires manually changing it? is there a way to use

System.Net.Dns.GetHostName() or similar to switch it automatically?

Thanks

3 Answers 3

1

Ayende has a post that addresses this issue.

http://ayende.com/blog/135169/frictionless-development-web-config-and-connection-strings

Sign up to request clarification or add additional context in comments.

Comments

0

In my software I just have 2 connection strings of the same name in my app.config and comment/uncomment to switch between configurations.

Another method is that you could create a static property in your solution (.asax file?) and just use that to swap between XYZDatabase-TEST and XYZDatabase when you are fetching ConnectionStrings.

Comments

0

Add connection string to your Web.config like:

<connectionStrings>
    <add name="XYZDatabase-TEST" connectionString="Server=.\SQLEXPRESS;Database=XYZDatabase-TEST";integrated security=SSPI;" providerName="System.Data.SqlClient" />
</connectionStrings>

Then open you Web.Release.config and add

<connectionStrings>
    <add name="XYZDatabase-TEST"
        connectionString="Data Source=OTHERSERVER;Initial Catalog=XYZDatabase-TEST;Persist Security Info=True;User ID=sa;Password=password" providerName="System.Data.SqlClient"
        xdt:Transform="SetAttributes"
        xdt:Locator="Match(name)"/>
</connectionStrings>

Now, everytime you will publish you application to deployment server using Release configuration it will use the connection string from web.release.config

Note that this transformation will not work locally when you debug. You must publish to run the web.config transformation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.