ConfigurationManager.OpenExeConfiguration

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • coltrane
    New Member
    • May 2010
    • 2

    ConfigurationManager.OpenExeConfiguration

    I am trying to store and retrieve connection string info from an app's config file and I am having trouble retrieving the connection string info.

    I stored the info with the following:

    Configuration config = null;
    config = configurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None );
    config.Connecti onStrings.Conne ctionStrings.Ad d(
    new ConnectionStrin gSettings(
    "MyConfiguratio nString",
    "Server=local;D atabase=Test;Pa ssword=password ;User Id=john;" ) );
    config.Save();

    I then to test I removed the Add method and use the following try to retrieve the configuration info with the following:

    Configuration config = null;

    config = ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None );

    string stuff = config.Connecti onStrings.Conne ctionStrings["MyConfiguratio nString"].ConnectionStri ng;

    this fails because the value

    config.Connecti onStrings.Conne ctionStrings["MyConfiguratio nString"];

    returns null;

    the configuration file has the following:

    <?xml version="1.0" encoding="utf-8"?>
    <configuratio n>
    <connectionStri ngs>
    <add name="MyConfigu rationString" connectionStrin g="Server=local ; Database=Test;P assword=passwor d;User Id=john;" />
    </connectionStrin gs>
    </configuration>


    thanks for the help

    john
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    #2
    Originally posted by coltrane
    I am trying to store and retrieve connection string info from an app's config file and I am having trouble retrieving the connection string info.

    I stored the info with the following:

    Configuration config = null;
    config = configurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None );
    config.Connecti onStrings.Conne ctionStrings.Ad d(
    new ConnectionStrin gSettings(
    "MyConfiguratio nString",
    "Server=local;D atabase=Test;Pa ssword=password ;User Id=john;" ) );
    config.Save();

    I then to test I removed the Add method and use the following try to retrieve the configuration info with the following:

    Configuration config = null;

    config = ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None );

    string stuff = config.Connecti onStrings.Conne ctionStrings["MyConfiguratio nString"].ConnectionStri ng;

    this fails because the value

    config.Connecti onStrings.Conne ctionStrings["MyConfiguratio nString"];

    returns null;

    the configuration file has the following:

    <?xml version="1.0" encoding="utf-8"?>
    <configuratio n>
    <connectionStri ngs>
    <add name="MyConfigu rationString" connectionStrin g="Server=local ; Database=Test;P assword=passwor d;User Id=john;" />
    </connectionStrin gs>
    </configuration>


    thanks for the help

    john
    What trouble are you facing.
    Can you show us the error. or some data

    Comment

    Working...