By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,971 Members | 1,467 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,971 IT Pros & Developers. It's quick & easy.

Accessing web.config with System.Configuration

P: n/a
I understand what's happening, but not why. I hope somebody else can
help me out.

I wrote a class library - DataAccess. This library can be included in
any type of application but for now is included in an ASP.NET
application. The connection strings for the DataAccess library are
contained in the web.config file but I wrote the library without
including System.Web (because it's not just for Web apps). So I get my
connection strings using System.Configuration.ConfigurationManager, not
System.Web.Configuration.WebConfigurationManager like the ASP.NET
components do. This works. It's fine that it does, but here's what's
confusing:

If I add an app.config (DataAccess.dll.config) file to DataAccess and
move the connection strings from web.config to DataAccess.dll.config,
the library can't get to them. I still use
System.Configuration.ConfigurationManager but I get a null reference on
the connectionStrings configuration key. Why can my libraries not have
their own configuration files? And why can my library access settings
from the web.config without using the WebConfigurationManager? This
doesn't make sense.

Optimally, I'd want to have DataAccess pull its connection strings from
DataAccess.dll.config unless they've been overridden by the hosting
application's settings. So the library could then be a plug & play
component and the developer writing an application that includes
DataAccess could override any configuration settings by including them
in the app.config or web.config for his/her application, while leaving
the DataAccess.dll.config file untouched.

Nov 22 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.