Change the app.config connection string during program load

Here is my issue. I have about 30 programs that I maintain. All of these programs will be moving in the near future. The database connection string that they use will also be changing about 2 to 3 times in the next 6 months. I want to program to update the app.config file when the program loads so that I don't have to change all the programs everytime a server is moved. Does the make sense. Any help is appreciated.
kashwmuAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vb_studentCommented:
i think you are looking at this the wrong way. the conection string is usally stored in a setting. thus you can set the connection string using the following syntax
my.settings.connstring = "some string"
my.settings.save
hope this helps reply if you need any more help.
0
rgn2121Commented:
Just a thought, something that I use with multiple apps that all access the same set of Oracle tables.  I use a Global file that my app.config points to...This file sits on a share that the app has access to and I just update the file, one location, for all of my apps.  I can post the small section of the app.config file that points to the Global file later tonight.
Also, your code will use the configuration.configurationmanager.appsettings
Just an alternative ...
0
13598Commented:
Set your connection strings under your Properties/Settings (type connectionstring, scope application).
Then you will be able to edit the app.config file and change the servername for the connection string(s) without having to rebuild or republish the apps.
0
rgn2121Commented:
Okay so, in order for me to access the Global file on a network share or where ever, I removed the settings from my app config file and then add the lines below just before the last 'configuration' tag.

<appSettings file="\\<your file path>\Global.config">
</appSettings>
Then the lines in my Global file look like this...
<appSettings>
 
  <add key="SMTPServerName" value="smtp.mydomain.com"/>
  <add key="DB_Connect_String" value="User Id=myname;Password=mypass;Data Source=something.mydomain.com;"/>

  </appSettings>
Then to access it from code I do the following (After adding a reference to System.configuration)
dim myConnection as string = configuration.configurationmanager.Appsettings("DB_Connect_String")
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kashwmuAuthor Commented:
I would say as a comment that the Global File contains only the lines listed there and not the normal config lines. That thew me for a min.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.