Results 1 to 6 of 6

Thread: Whats Wrong? - XML config file problems

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2003
    Posts
    93

    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

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    In the xml the node should be 'appSettings' not 'appsettings' it is case sensitive.

  3. #3
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Wink

    Edneesis, how long did it take you to find that flaw?

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2003
    Posts
    93
    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

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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
  •  



Click Here to Expand Forum to Full Width