Configuration.AppSettims returns Nothing

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi - can anyone please help this is driving me up the wall!! I have a config file

<?xml version="1.0" encoding="utf-8"?><configuration><appSettings><add key="connectString" value="server=DEV1-SMCT\NIIR;database=DBName;uid=username;password=password" /></appSettings></configuration
(In final release I won't have passwords in this!!

And when I load my first form I try and retrieve the value usin

str_Connection = ConfigurationSettings.AppSettings("connectString"

And every time this returns Nothin

I also tried the line str_Connection = ConfigurationSettings.AppSettings.Item("connectString").ToString but just gives an error because the object is nothing

I hope someone can point the obvious that I must be missing!
Thank
Siobha
PS Apologies - I am posting this again as I originally posted as a response to someone elses old post - just in case it doesn't get spotted
 
First of all, I'm not sure if youre working with a winform or web
application.

If you're working with a web application, make sure the filename is
web.config. If you're working with a winforms application, make sure the
filename is <YourExeName>.exe.config.

So, if your project outputs an assembly named MyProject.exe, then your
config filename should be MyProject.exe.config. This file should also be
located in the same folder as the executable.

Lastly, if you're using VS.NET, you should be able to add a file named
app.config to a winforms project, and it will take care of everything
for you. However, I pointed out the steps so that you could verify that
it is working properly.
 
Back
Top