Results 1 to 5 of 5

Thread: updating app.config connection string at runtime [* Resolved *]

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Resolved updating app.config connection string at runtime [* Resolved *]

    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 .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
    Last edited by steve_rm; Sep 26th, 2006 at 02:57 AM.
    steve

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: updating app.config connection string at runtime

    You can't update the .config file, but you can store your settings in another xml file which you can update and read from as you please.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: updating app.config connection string at runtime

    This is a duplicate post AND it's in the wrong forum.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: updating app.config connection string at runtime

    steve

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: updating app.config connection string at runtime [* Resolved *]

    New information. I like it. I would have liked it better in original thread in the proper forum though.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width