?
Solved

URGENT - C# Windows App Config File

Posted on 2005-04-24
9
Medium Priority
?
302 Views
Last Modified: 2011-08-18
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?
0
Comment
Question by:Kyle Abrahams
9 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 13854911
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
 
LVL 41

Author Comment

by:Kyle Abrahams
ID: 13855157
anyway to make it compile and put it in the debug bin then?
0
 
LVL 41

Author Comment

by:Kyle Abrahams
ID: 13855165
Also just tried it that way (to try to brute force it)  It didn't work there either.

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 37

Expert Comment

by:gregoryyoung
ID: 13855166
your config file isn't "compiled".

other key part is the name of the file.

Greg
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 13855170
you said test.config....

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

Cheers,

Greg
0
 
LVL 41

Author Comment

by:Kyle Abrahams
ID: 13855325
I switched  it to test.exe and test.exe.config.   Still no luck.

0
 
LVL 8

Accepted Solution

by:
vinhnl earned 1400 total points
ID: 13855372
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
 
LVL 14

Assisted Solution

by:existenz2
existenz2 earned 600 total points
ID: 13855511
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
 
LVL 41

Author Comment

by:Kyle Abrahams
ID: 13862270
Solution presented:

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

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question