Is it possible to modify the connectionstrings defined in the app.config/web.config at runtime? I want to use different configfiles depending on the machine the app/site is run on (only for debugging purposes, of course. We’ll use the regular config files when deployed).
I can write AppSettings, but not ConnectionStrings (AFAIK). Or can I?
Yes it’s possible, but AFAIK only via Reflection. The following code should do what you need (read below for usage):
assemblyMemberis the calling typesettingsClassis the type of your settings classnewConnectionStringis the full string to setconnectionStringKeyis the name of the connection string that you defined in your app’s settingsYou should call this method as soon as possible after your app has started, preferably in the Main() method.