Configuration file read problem

S

Steve Enzer

I need to use a configuration file to set the connection string for the ado
data connector in my project, but I'm having trouble reading the config
file.

My config file contains the following:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings> <add key="ConnectionString" value="server=localhost;user
id=root;password=pw;database=aceinventory;pooling=false"/>
</appSettings>
</configuration>

The file is named ACE_Inventory.config where ACE_Inventory is the name of
the project's exe file and is located in the project's bin folder.

I'm using the following line to read the file:
sInventoryConnection =
System.Configuration.ConfigurationSettings.AppSettings("ConnectionString")

Unfortunately, this does not read the config file.

I'd sure appreciate any advice.

Thanks, Steve Enzer
 
S

Steve Enzer

I've tried that, as that is what the Microsoft documentation says to do.
But as soon as I run the app in debug mode, Visual Studio immediately
deletes the file.
 
P

Phil G.

Steve,

try this. Add a new item to your project and select the Application
Configuration. Don't change the default name app.config. Now open this
config file and copy/paste from your original into this new one.

Now, when you build your project it will automatically create the
project.exe.config file for you and place it in the bin folder!

HTH, Phil
 
S

Steve Enzer

Phil, this finally worked. I spent a lot of time going thru Microsoft's
help files and it's too bad they weren't more explicit about this topic.

Much thanks,
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top