M
Mark
I am trying to read the appsettings section of a configuration file
using the ConfigurationManager object (ASP.NET application) with the
following three lines but for some reason the ConfigurationManager does
not recognize there is an appSettings section in the file and the last
line throws an exception. It opens successfully but the collection is
empty. Any thoughts as to why?
Configuration configFile =
ConfigurationManager.OpenExeConfiguration(configFileAndPath);
string keyToUse = string.Empty;
keyToUse =
configFile.AppSettings.Settings["ConnectionStringToUse"].Value;
Below is my configuration file and you can certainly see that it has an
appSettings section. Any help would be appreciated.
Thanks
Mark
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="Development"
connectionString="server=127.0.0.1;Application Name=Generic
Security;Database=GenericSecurity; Integrated Security = SSPI; Pooling
= True; Connection Lifetime = 15; Min Pool Size=1; Max Pool Size=1"
providerName="System.Data.SqlClient" />
<add name="Test" connectionString="data source=127.0.0.1;Integrated
Security=SSPI;Initial Catalog=GenericSecurity; MinPoolSize=1;
MaxPoolSize=1" providerName="System.Data.SqlClient" />
<add name="Production" connectionString="data
source=127.0.0.1;Integrated Security=SSPI;Initial
Catalog=GenericSecurity; MinPoolSize=1; MaxPoolSize=1"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="ConnectionStringToUse" value ="Development"/>
</appSettings>
</configuration>
using the ConfigurationManager object (ASP.NET application) with the
following three lines but for some reason the ConfigurationManager does
not recognize there is an appSettings section in the file and the last
line throws an exception. It opens successfully but the collection is
empty. Any thoughts as to why?
Configuration configFile =
ConfigurationManager.OpenExeConfiguration(configFileAndPath);
string keyToUse = string.Empty;
keyToUse =
configFile.AppSettings.Settings["ConnectionStringToUse"].Value;
Below is my configuration file and you can certainly see that it has an
appSettings section. Any help would be appreciated.
Thanks
Mark
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="Development"
connectionString="server=127.0.0.1;Application Name=Generic
Security;Database=GenericSecurity; Integrated Security = SSPI; Pooling
= True; Connection Lifetime = 15; Min Pool Size=1; Max Pool Size=1"
providerName="System.Data.SqlClient" />
<add name="Test" connectionString="data source=127.0.0.1;Integrated
Security=SSPI;Initial Catalog=GenericSecurity; MinPoolSize=1;
MaxPoolSize=1" providerName="System.Data.SqlClient" />
<add name="Production" connectionString="data
source=127.0.0.1;Integrated Security=SSPI;Initial
Catalog=GenericSecurity; MinPoolSize=1; MaxPoolSize=1"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="ConnectionStringToUse" value ="Development"/>
</appSettings>
</configuration>