URGENT - C# Windows App Config File

Hi All,

For Some reason my windows app isn't pulling the config settings and it's driving me nuts.  
Added the config through solution explorer.  Named it test.config

My Config File:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <appSettings>
   <add key="dbConnString" value="server=127.0.0.1;uid=sa;pwd=;database=Northwind" />
 </appSettings>
</configuration>

Accessing in the code like this:
private String dbConnString = ConfigurationSettings.AppSettings ["dbConnString"];


Am I missing something?  I haven't touched the assembly at all, do I need to add it to GAC or anything before the config will take effect?
LVL 42
Kyle AbrahamsSenior .Net DeveloperAsked:
Who is Participating?
 
vinhnlCommented:
Please create file app.config in same directory of solution.

OR

Please create file test.exe.config in output directory (your solution directory/bin/debug).
0
 
gregoryyoungCommented:
http://www.c-sharpcorner.com/Code/2002/April/XMLConfigInWinForms.asp

note in particular

"The configuration file should be in the same directory as the application. The name of the configuration file should have the same name as the application with .config at the end. For example, an application called Watcher.exe should have a configuration file called Watcher.exe.config."
0
 
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
anyway to make it compile and put it in the debug bin then?
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
Also just tried it that way (to try to brute force it)  It didn't work there either.

0
 
gregoryyoungCommented:
your config file isn't "compiled".

other key part is the name of the file.

Greg
0
 
gregoryyoungCommented:
you said test.config....

for test.exe ... it should be named test.exe.config

Cheers,

Greg
0
 
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
I switched  it to test.exe and test.exe.config.   Still no luck.

0
 
existenz2Commented:
In addition to vinhnl's answer:

App.config:
Adding App.config to your solution will allow VS.NET to compile the config file also during debugging or releasing. It will the automatically create the right filename for you.

test.exe.config:
If your application is named "test" the compiler will generate a test.exe and the configreader will look for test.exe.config. If you rename it to this filename you need to place it in the output directory, so it will be used. Biggest problem is that it wont work during debug then.

So I suggest you to use the given App.config method. That works the best for both debugging and releasing.
0
 
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
Solution presented:

I deleted ALL config files.  Created 1 new config named app.config.  It now works :-).  Thanks very much for your help.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.