Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update a connection string in app.config at runtime

Status
Not open for further replies.

steve1rm

Programmer
Aug 26, 2006
255
GB
Hello,

I want to be able to update a connection string that I have in my app.config file. This is so that the customer can change the connection to another server or database.

Can anyone give me any example code. I am using Visual Basic 2005.

Many thanks in advance,

Steve
 
Hello

I am using my.settings to create a application scope connection string.

My problem I have into the setting and create a connection string (easy). But I don't know and can't find out to update and save the new connection string.

My.Settings.cnnString = "This is example connection" 'Error read-only property

I am using vb.net 2005

Can anyone help,

Thanks in advance,

Steve
 
Hello

I am using my.settings to create a application scope connection string.

The customer would like to change this if they want to connect to another database, and this should update the app.config file with the updated connection string.

My problem I have into the setting and create a connection string (easy). But I don't know and can't find out to update and save the new connection string.

My.Settings.cnnString = "This is example connection" 'Error read-only property

I am using vb.net 2005

Can anyone help,

I got this code and it seem it would work. However, there is a problem with the code. I get a "Object reference not set to an instance of an object."

Here my code.
Code:
Dim config As Configuration.Configuration = Configuration.ConfigurationManager.OpenExeConfiguration(Configuration.ConfigurationUserLevel.None)
        config.ConnectionStrings.ConnectionStrings("ServiceMasterConnectionString").ConnectionString = "This is new connection " 'Error - 
        config.Save()

Thanks in advance,

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top