C
CaptainCaveman
Hi,
I'm trying to manage the Connection String from my app.config file.
I would like to read it in, amend it so that it contains a specific
datasource, then write it back.
My ConfigFile is named project.config, and the code I am trying to use
follows.
FILE ************************
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="Project.Properties.Settings.DatabaseConnectionString"
connectionString="Data Source=MyPC\SQLEXPRESS;Initial
Catalog=Database;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
CODE ***************************
ConnectionStringSettingsCollection cs =
ConfigurationManager.ConnectionStrings;
for (int nItem = 0; nItem < cs.Count; nItem++)
{
String str =
cs["Project.Properties.Settings.DatabaseConnectionString"].Name;
Console.WriteLine(str);
}
I keep getting an object not set to an instance of an object error. I
thought that the settings were loaded at runtime.
Could anyone help please in telling me how I have initialised this wrongly,
and how I should be reading the ConnectionStrings information.
TIA
CC
I'm trying to manage the Connection String from my app.config file.
I would like to read it in, amend it so that it contains a specific
datasource, then write it back.
My ConfigFile is named project.config, and the code I am trying to use
follows.
FILE ************************
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="Project.Properties.Settings.DatabaseConnectionString"
connectionString="Data Source=MyPC\SQLEXPRESS;Initial
Catalog=Database;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
CODE ***************************
ConnectionStringSettingsCollection cs =
ConfigurationManager.ConnectionStrings;
for (int nItem = 0; nItem < cs.Count; nItem++)
{
String str =
cs["Project.Properties.Settings.DatabaseConnectionString"].Name;
Console.WriteLine(str);
}
I keep getting an object not set to an instance of an object error. I
thought that the settings were loaded at runtime.
Could anyone help please in telling me how I have initialised this wrongly,
and how I should be reading the ConnectionStrings information.
TIA
CC