C
CoderHead
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.
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.