|
-
Aug 25th, 2003, 03:39 PM
#1
Thread Starter
Lively Member
Whats Wrong? - XML config file problems
Can anyone tell me where I've gone wrong with this?
Code so far for config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appsettings>
<add key="ConnectionString" value="data source=STKPROD04;initial catalog=STKPRODDB;integrated security=SSPI;persist security info=False" />
</appsettings>
</configuration>
Code in module:
Imports System.Configuration
Imports System.Collections.Specialized
Module ModSubMain
Sub Main()
Dim sAttr As String
sAttr = System.Configuration.ConfigurationSettings.AppSettings("ConnectionString")
Debug.WriteLine("The value of key: " & sAttr)
Dim sAll As NameValueCollection
sAll = ConfigurationSettings.AppSettings()
End Sub
End Module
When this runs I receive an error message:
An unhandled exception of type 'System.Configuration.ConfigurationException' occurred in system.dll
Additional information: Unrecognized configuration section appsettings
This error is received on the line:
sAttr = System.Configuration.ConfigurationSettings.AppSettings("ConnectionString")
Can anyone see what I have wrong with this code? I'm just trying to create a very simple connection via a config file and have been having a terrible time. Any help ??
Thanks,
Corinne
-
Aug 25th, 2003, 03:50 PM
#2
In the xml the node should be 'appSettings' not 'appsettings' it is case sensitive.
-
Aug 25th, 2003, 05:18 PM
#3
I wonder how many charact
Edneesis, how long did it take you to find that flaw?
-
Aug 25th, 2003, 05:30 PM
#4
You mean right now or the first time I learned it was case sensitive?
Right now just a second, it was the first thing I checked. We VBers aren't used to case sensitive so it can be trouble we its forced on us, at least for me its that way.
If you mean the first time, then I don't really remember how long it took but I do remember how pissed off I was just before I figured it out.
-
Aug 26th, 2003, 07:26 AM
#5
Thread Starter
Lively Member
Edneeis,
Thank you so much for spotting the error in my code. I had read that the XML file was case sensitive but I was thinking that since I "cased" the appSettings the same way in each line I was OK.
A followup question. Can you explain the relationship between the config files. The ones I have a question about are:
AppName.exe.config
AppName.config
AppName.exe
Exactally where should these reside in the project folder and if a change is made to the code for the XML file which file should it be made in? Currently my project has AppName.config in the root folder and AppName.exe.config, AppName.config, AppName.exe in the bin folder. Is this correct?
Thanks,
Corinne
-
Aug 26th, 2003, 10:15 AM
#6
AppName.exe.config - This is the actual config file that the exe will use and must be in the same folder as the exe.
AppName.config - Is the designtime representative of the config file and should be in the project folder with all the source code. This should also be called app.config instead of the application name.
AppName.exe - This is your compiled application.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|