Results 1 to 5 of 5

Thread: Updating conn string at run time

Threaded View

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Updating conn string at run time

    I dont get this.
    I have figured out how to read then update settings in my app.config at run time using the following exert:
    Code:
    Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
    ConfigurationSectionGroup grpApp = config.GetSectionGroup("applicationSettings");
    ClientSettingsSection secPropSet = (ClientSettingsSection)grpApp.Sections[sSettingsSection];
    secPropSet.SectionInformation.ForceSave = true;
     SettingElement elm = secPropSet.Settings.Get(SettingName);
    elm.Value.ValueXml.InnerText = NewValue.Trim();
    config.Save()
    This works fine with custom sections but not with <connectionStrings>.
    Reading the connection strings can be done using the following exert :
    Code:
                //conn strings
    ConnectionStringsSection connStringSection = config.ConnectionStrings;
     ConnectionStringSettingsCollection connectionStringsCollection = connStringSection.ConnectionStrings;
    System.Collections.IEnumerator connStringsEnum = connectionStringsCollection.GetEnumerator();
    int i = 0;
     while (connStringsEnum.MoveNext())
    { ///blah blah
    
    }
    For the life of me I cannot figure out how to write an update made against a connection string.
    Last edited by venerable bede; Mar 17th, 2008 at 09:56 AM.

    Parksie

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