[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
Re: [02/03]Problem Retrieving a Connection String from App.Config
Have you manually opened the file to ensure ("Tshwane_Train") really does exist?
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
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"/>
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: <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
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"/>
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: <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
Re: [02/03]Problem Retrieving a Connection String from App.Config
Value should be (small case)
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
Re: [02/03]Problem Retrieving a Connection String from App.Config
change to it should work
Code:
"uid=sde;Password=topology;Database=Tshwane_Valuations_Train;Server=SGIICORNETGS01"
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
Re: [Resolved]][02/03]Problem Retrieving a Connection String from App.Config
Glad that worked for you ;)