From: coltrane on
I am trying to store and retrieve connection string info from config
file and I am having trouble retrieving the connection string info.

I stored the info with the following:

Configuration config = null;
config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None );
config.ConnectionStrings.ConnectionStrings.Add(
new ConnectionStringSettings(
"MyConfigurationString",
"Server=local;Database=Test;Password=password;User Id=john;" ) );
config.Save();

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

Configuration config = null;

config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None );

string stuff =
config.ConnectionStrings.ConnectionStrings["MyConfigurationString"].ConnectionString;

this fails because the value

config.ConnectionStrings.ConnectionStrings["MyConfigurationString"];

returns null;

the configuration file has the following:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="MyConfigurationString"
connectionString="Server=local; Database=Test;Password=password;User
Id=john;" />
</connectionStrings>
</configuration>


please excuse the formatting, thunderbird messages are a little hard to
work with

thanks for the help

john