Is there a way to override a ConnectionString in an app.config. Our buildsystem runs also on a server of a customer, but there the connectionString needs to be different. Because the app.config is in svn, everytime I change something in the app.config and commit it, I need to go to the server of the customer to change the connectionString back to their database…
In ant-scripts for example, this is no problem, but in an app.config I can’t seem to find a way. Tried this for example:
<connectionStrings configSource="WebConnectionString.config">
<add name="ConnectionString"
connectionString="..."
providerName="System.Data.SqlClient"/>
</connectionStrings>
What I’m trying to do is that if WebConnectionString.config exists, then use the connectionString in that config file. If it doesn’t, use the one defined in code sample (so, in app.config).
You could do following, create a class where you encapsulate the retrieval of the connection string.
something like this
and the usage would be something like this
hope that helps