problems with config file in multi-project solution

G

Guest

Hi all,

I have a solution with 4 projects: a class library, a windows app, a windows
service, and an installer project. The class library handles all
communication with the database and its classes are used by both the
application and the service. I have stored the database connection string in
an app.config file located in the class library project.

Everything was working fine on my dev box, but when I migrated to the QA
box, I started getting a "connection string not initialized" error. When I
hard code the connection string in each of the class files, everything works
fine, which leads me to believe that the problem is that the app.config file
is not being read. The code I'm using in each of my class files is:
SqlConnection conn = new
SqlConnection(ConfigurationSettngs.AppSettings["whitney"]);

Questions: since the class library is the only project that connects to the
database, is it the only project that should have an app.config file with the
connection string? Do I need to explicitly add the app.config file to my
installer project? What could I be doing wrong?

Thanks in advance for your help!

Brian
 
N

Nick Malik

nope.

Your class library does not have a config file and it will not have one. I
have no idea how you've been access a config file in testing, but in
production, you will use the config file for the exe, not the dll.
Therefore, both your windows app and your windows service will need to
either have the connection string, or refer to a config file that does.

I addressed the issue of having a config file for a dll in a recent blog
posting. It may help...
http://blogs.msdn.com/nickmalik/archive/2004/11/25/270420.aspx

--- Nick
 
G

Guest

Thanks Nick,

I took the config file out of the library project, put a copy in both the
windows app and service projects, and everything works like a charm. Not sure
why it was working on my dev box...

Thanks!

Nick Malik said:
nope.

Your class library does not have a config file and it will not have one. I
have no idea how you've been access a config file in testing, but in
production, you will use the config file for the exe, not the dll.
Therefore, both your windows app and your windows service will need to
either have the connection string, or refer to a config file that does.

I addressed the issue of having a config file for a dll in a recent blog
posting. It may help...
http://blogs.msdn.com/nickmalik/archive/2004/11/25/270420.aspx

--- Nick
bmcelhany said:
Hi all,

I have a solution with 4 projects: a class library, a windows app, a windows
service, and an installer project. The class library handles all
communication with the database and its classes are used by both the
application and the service. I have stored the database connection string in
an app.config file located in the class library project.

Everything was working fine on my dev box, but when I migrated to the QA
box, I started getting a "connection string not initialized" error. When I
hard code the connection string in each of the class files, everything works
fine, which leads me to believe that the problem is that the app.config file
is not being read. The code I'm using in each of my class files is:
SqlConnection conn = new
SqlConnection(ConfigurationSettngs.AppSettings["whitney"]);

Questions: since the class library is the only project that connects to the
database, is it the only project that should have an app.config file with the
connection string? Do I need to explicitly add the app.config file to my
installer project? What could I be doing wrong?

Thanks in advance for your help!

Brian
 

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