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?
 
rgn2121Connect With a Mentor Commented:
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.