Results 1 to 3 of 3

Thread: Configuration file not saving runtime (not debugging)

  1. #1

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Configuration file not saving runtime (not debugging)

    I am using the code below to save connection string during runtime (Clie)

    Code:
                Try
                    connStr = String.Format("SERVER={0}; PORT={1}; USER={2}; PWD={3}; DATABASE={4};", _
                                        txtServer.Text, nudPort.Value, txtUser.Text, txtPass.Text, txtDB.Text)
                    Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
                    Dim section As ConnectionStringsSection = DirectCast(config.GetSection("connectionStrings"), ConnectionStringsSection)
                    section.ConnectionStrings("MySQL").ConnectionString = connStr
                    If section IsNot Nothing Then
                        If Not section.IsReadOnly() Then
                            section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider")
                            section.SectionInformation.ForceSave = True
                            config.Save(ConfigurationSaveMode.Modified)
                        End If
                    End If
                    ConfigurationManager.RefreshSection("connectionStrings")
                Catch ex As Exception
                    ShowMessage(String.Format(My.Resources.error_item_failed, "save", "Config"), MessageBoxIcon.Information)
    
                End Try
    the configuration is not saving however, i notice this when i restart the application and check the config from the application

    How do i modify configuration settings, especially connection string at runtime (not debug)
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

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

    Re: Configuration file not saving runtime (not debugging)

    Does it only appear to fail to save if you make a code change and then run the project again? What if you just exit the app and run it again immediately? It may well be that your modified config file is simply being overwritten when you build again, which will happen if there's a code change.
    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

  3. #3

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: Configuration file not saving runtime (not debugging)

    i am talking about a deployed vb.net application, not in visual studio
    when i exit the application at start it again, after i must have supplied the correct settings, i see the old values not the new one i wanted saved
    Last edited by coolcurrent4u; Sep 6th, 2016 at 07:49 AM.
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

Tags for this Thread

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