G
Guest
Hi,
Am having trouble retrieving a value from a config file using VC# 2005.
app.config file (as created using 'Settings' tab on Project properties page)
is as follows:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="TestSQL.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<TestSQL.Properties.Settings>
<setting name="SQLDatabase" serializeAs="String">
<value>server=(local);uid='sa';pwd=''</value>
</setting>
</TestSQL.Properties.Settings>
</applicationSettings>
</configuration>
The code I am using to try to access the SQLDatabase value is:
AppSettingsReader appReader = new AppSettingsReader();
string conn = (string)appReader.GetValue("SQLDatabase", typeof(string));
When the second line is executed, I get an InvalidOperationException saying
that "The key 'SQLDatabase' does not exist in the appSettings configuration
section."
Except it does exist. Cant see anything wrong - no problem with case even -
but I wonder about the namespace in the app.config file that encloses by
value. This corresponds with the default namespace for the project, which is
an ordinary WindowsApplication.
Any idea why I am getting this problem?
Thanks
Ian
Am having trouble retrieving a value from a config file using VC# 2005.
app.config file (as created using 'Settings' tab on Project properties page)
is as follows:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="TestSQL.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<TestSQL.Properties.Settings>
<setting name="SQLDatabase" serializeAs="String">
<value>server=(local);uid='sa';pwd=''</value>
</setting>
</TestSQL.Properties.Settings>
</applicationSettings>
</configuration>
The code I am using to try to access the SQLDatabase value is:
AppSettingsReader appReader = new AppSettingsReader();
string conn = (string)appReader.GetValue("SQLDatabase", typeof(string));
When the second line is executed, I get an InvalidOperationException saying
that "The key 'SQLDatabase' does not exist in the appSettings configuration
section."
Except it does exist. Cant see anything wrong - no problem with case even -
but I wonder about the namespace in the app.config file that encloses by
value. This corresponds with the default namespace for the project, which is
an ordinary WindowsApplication.
Any idea why I am getting this problem?
Thanks
Ian