Loading connection strings from class library in web application
I have a fairly straightforward problem that I imagine has a simple solution. However, it's not clear to me. Here's the problem:
I have a web application that references a class library. That class library needs to access the connection strings i开发者_如何转开发n the web.config. From what I've read, this shouldn't be a problem.
Here's the code that I'm using to access the connection strings:
Dim connectionStrings As ConnectionStringSettingsCollection = ConfigurationManager.ConnectionStrings
When I run this code in the web application, I get all of my connection strings back. However, when this exact same code is run in the class library (called from the web application), it reverts to the machine.config for some reason and gets the entry from there. i.e.
data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true
I'm not sure if it matters or not, but the web side of this is a WCF RIA services web site that backs a Silverlight application. I didn't see anything funny in the config that could justify this strange behavior. Any thoughts on why I'm seeing this behavior?
Thanks,
MattThere's a "WebConfigurationManager" Class, I guess it may solve your problem.
精彩评论