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
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
Comment