views:

34

answers:

1

Hi

I have an automated build process that sets up the application for a specified mode (e.g. Dev, uat, live). Depending on this mode I want to update Connection Strings to the relevant one.

However, in my Data Access Layer there is an app.config file which stores the connection string and this is used to feed the Settings.Settings file. In my builder I update the app.config's xml with the new Connection String and then the solution is built, however the Settings.setting file doesn't get regenerated with the updated app.config connection string and so the app doesn't connect to the correct DB.

Is it possible to do this or am I going about it the wrong way through a misunderstanding of how these config/settings files work?

Thanks Stuart

+1  A: 

Yeah, you're doing it backwards. The IDE generates the .config file contents from the settings you define in the Settings designer. That doesn't work the other way around. If getting the connection string valid straight from the build is important then set the default in the Settings designer. Or don't store it in a setting.

Hans Passant
Thanks for your reply! I had previously tried to update the Connection String in the Settings.Designer.cs file but it is split over two lines and in plain text which makes it a lot harder to change automatically. Do you have any ideas of other ways to do this?
Stuart
I don't get the "change automatically" requirement. Ultimately it will always have to be changed by hand to match the deployed dbase server name and location. If this should be automatic then using a setting might not be the proper solution. Also consider, say, SqlConnectionStringBuilder to generate it at runtime.
Hans Passant
By Change Automatically i mean automatically by the Builder process. At the moment to create a build I have to open the settings file and manually edit the connection string. I would like to be able to have the builder replace the connection string in these files by itself. The builder has the capability to query XML and replace values which was why I was looking to change the app.config.
Stuart