1

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 in 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,
Matt

2
  • This question may be related to your problem: stackoverflow.com/questions/4939577/… Commented Apr 11, 2011 at 3:51
  • @patmortech - I don'tn think this is the sae problem. The author states, "If I paste the connection string back into the Web.Config it all works just fine", however, this is not the case for me (I would happily accept the situation if it were and Consider this questions resolve. Any other thoughts? Commented Apr 12, 2011 at 11:01

1 Answer 1

0

There's a "WebConfigurationManager" Class, I guess it may solve your problem.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer. I should've mentioned that my class library references the entity framework, which uses the ConfigurationManager internally, so using the WebConfigurationManager is not an option. The class library shouldn't know anything about web environment anyway, so that would probably not be a good solution anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.