Results 1 to 12 of 12

Thread: [Resolved]][02/03]Problem Retrieving a Connection String from App.Config

  1. #1

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    Question [Resolved]][02/03]Problem Retrieving a Connection String from App.Config

    Hi all

    i have the Following App.Config file in VB2003 and a Windows Application.

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    	<appSettings>
    		<!--   User application and configured property settings go here.-->
    		<!--   Example: <add key="settingName" value="settingValue"/> -->
    		<add key="timer.Enabled" value="True" />
    		<add key="timer.Interval" value="1000" />
    		<connectionstring>
    		<add name = "Tshwane_Train"
    		ConnectionString = "login=sa;Password=tfjgssf;Database=Tshwane_Valuations_Train;
    		Server=SGIICOR"/>
    		</connectionstring>
    		
    		</appSettings>	
    </configuration>
    and am Accessing this Connction string from the Vb App, like this

    Code:
    Dim constr As String = Configuration.ConfigurationSettings.AppSettings("Tshwane_Train")
    Wheni compile the Application, i get no Errors ,but but when i try to run the application, i mean the Part that will need to Connect to the Database i get the Following Error.

    Code:
    An unhandled exception of type 'System.Configuration.ConfigurationException' occurred in system.dll
    
    Additional information: Unrecognized element
    What is Wrong

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [02/03]Problem Retrieving a Connection String from App.Config

    Have you manually opened the file to ensure ("Tshwane_Train") really does exist?

  3. #3

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    Question Re: [02/03]Problem Retrieving a Connection String from App.Config

    yes ,

    it shows in the App.Config File i have posted. am i missing Something? , If i write the name in the App.Config file do i have to write it somewhere else again.

    Thanks

  4. #4
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: [02/03]Problem Retrieving a Connection String from App.Config

    replace
    Code:
    <connectionstring>
    		<add name = "Tshwane_Train"
    		ConnectionString = "login=sa;Password=tfjgssf;Database=Tshwane_Valuations_Train;
    		Server=SGIICOR"/>
    		</connectionstring>
    with

    Code:
    <add name = "Tshwane_Train"
    		value= "login=sa;Password=tfjgssf;Database=Tshwane_Valuations_Train;
    		Server=SGIICOR"/>
    __________________
    Rate the posts that helped you

  5. #5

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    Question Re: [02/03]Problem Retrieving a Connection String from App.Config

    hi man

    Thanks for your help, i have changed the App.Config file to the way you advised like and it looked like this

    Code:
    <configuration>
    	<appSettings>
    		<!--   User application and configured property settings go here.-->
    		<!--   Example: &lt;add key="settingName" value="settingValue"/> -->
    		<add key="timer.Enabled" value="True" />
    		<add key="timer.Interval" value="1000" />
    		<add name = "Tshwane_Train"
    		Value= "login=sde;Password=topology;Database=Tshwane_Valuations_Train;
    		Server=SGIICORNETGS01"/>
        </appSettings>	
    </configuration>
    and the Code in my VB is Still the Same
    Code:
    Dim constr As String = Configuration.ConfigurationSettings.AppSettings("Tshwane_Train")
    and it Throws an Error that says


    Code:
    An unhandled exception of type 'System.Configuration.ConfigurationException' occurred in system.dll
    
    Additional information: Required attribute 'key' not found
    Thanks

  6. #6
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: [02/03]Problem Retrieving a Connection String from App.Config

    remove additional space....

    Code:
    <add name = "Tshwane_Train"
    		Value= "login=sde;Password=topology;Database=Tshwane_Valuations_Train;
    		Server=SGIICORNETGS01"/>
    should be

    Code:
    <add name="Tshwane_Train"
    		value="login=sde;Password=topology;Database=Tshwane_Valuations_Train;
    		Server=SGIICORNETGS01"/>
    Edit :
    Code:
    <add key="Tshwane_Train"
    		value="login=sde;Password=topology;Database=Tshwane_Valuations_Train;
    		Server=SGIICORNETGS01"/>
    Last edited by riteshjain1982; Jun 17th, 2008 at 09:16 AM.
    __________________
    Rate the posts that helped you

  7. #7

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    Question Re: [02/03]Problem Retrieving a Connection String from App.Config

    hi, now my App.Config will look like this

    Code:
    <configuration>
    	<appSettings>
    		<!--   User application and configured property settings go here.-->
    		<!--   Example: &lt;add key="settingName" value="settingValue"/> -->
    		<add key="timer.Enabled" value="True" />
    		<add key="timer.Interval" value="1000" />
    		<add key="Tshwane_Train"
    						Value="login=sde;Password=topology;Database=Tshwane_Valuations_Train;
    						Server=SGIICORNETGS01"/>
        </appSettings>	
    </configuration>
    i have removed the Space as Advised and i have this Error


    Code:
    An unhandled exception of type 'System.Configuration.ConfigurationException' occurred in system.dll
    
    Additional information: Required attribute 'key' not found
    Thanks

  8. #8
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: [02/03]Problem Retrieving a Connection String from App.Config

    Value should be
    Code:
    value
    (small case)
    __________________
    Rate the posts that helped you

  9. #9

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    Question Re: [02/03]Problem Retrieving a Connection String from App.Config

    Wow thanks man

    We are Getting Somewhere now, why does it resfuse the login, Doesnt it treat it like a String, ok, after i fixed that m, i got the Following Error

    Code:
    Additional information: Keyword not supported: 'login'.
    Thanks man you are a Star

  10. #10
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: [02/03]Problem Retrieving a Connection String from App.Config

    change
    Code:
    login
    to
    Code:
    user id or uid
    it should work

    Code:
    "uid=sde;Password=topology;Database=Tshwane_Valuations_Train;Server=SGIICORNETGS01"
    __________________
    Rate the posts that helped you

  11. #11

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    Resolved Re: [02/03]Problem Retrieving a Connection String from App.Config

    I would like to take this Chance to Thank you for your Patience and your help. I have Added a Reputation to your Answers. you are not just a Good Developer but a A Good Person. if you Continue with that attitude you will go places , mybe as am talking you are places , because people have seen what you got.

    Thanks man

  12. #12
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: [Resolved]][02/03]Problem Retrieving a Connection String from App.Config

    Glad that worked for you
    __________________
    Rate the posts that helped you

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