Where to put configuration information in a Windows app?

  • Thread starter Thread starter Geoff Pennington
  • Start date Start date
G

Geoff Pennington

It is really pathetic that I don't know this, but here it is. I have been
writing ASP.Net apps for a while, and all configuration information, such as
the database connection string, goes in a text file called Web.config.
There, it is accessible to the entire app and can be changed without
recompiling anything.

Now I am writing a Windows app (using VB.Net). This type of project does not
have a Web.config file (of course) so where do I put the database connection
strings, so that I don't have to recompile if the DB location changes?

Much obliged,
Geoff.
 
Geoff,
Add a "app.config" to your VS.NET project. When you compile the project it
will be named for the executable. For example myproject.exe has
myproject.exe.config.

Because of the ability to set which version of the runtime should be used,
VS.NET 2003 always replaces the myproject.exe.config in the output folder.

You need to add your config file to your VS.NET project's root folder as
app.config, it needs to be named "app.config" without the quotes. When you
build your project VS.NET (both 2002 & 2003) will copy the app.config file
from the project root to your output folder and name it appropriately
(myproject.exe.config).

Note the format of the app.config & web.config are the same, obviously some
web specific sections do not apply to Windows Forms.

Hope this helps
Jay
 
Add a "app.config" to your VS.NET project. When you compile the project it
will be named for the executable. For example myproject.exe has
myproject.exe.config.
...
Note the format of the app.config & web.config are the same, obviously some
web specific sections do not apply to Windows Forms.

Note also that a third config file exists:

C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\CONFIG\machine.config

If you only have one database server and your connection string is
invariant, you may wish to place it there. A local entry in app.config
will override the machine.config entry.

I used this technique so that when I take work home (where the
connection string is different), I don't have to edit a config file.

-- Rick
 
Thanks to both. I think I'm on the right track now. Jeesh, this stuff can be
maddening to try and find in the "help" files!
 
Back
Top