Sunday, February 19, 2012

how to access web.config

I am using vs2005 and have a solution file with 4 projects, 2 of which are presentation layers (admin sections), 1 is a business logic layer, the other a data access layer.

The data access layer project is simply a class library that will provide data access functionality. Im using a dataset (xsd) to create my data access objects. My question is how do I select a connection string from the web config file (which is in each of the presentation layer projects) as the data access layer is a class library there is no web.config. Using the connection string selector in the dataset wizard doesnt show any available connection strings.

Reference the System.Confiuration dll and you can use the System.Configuration classes to obtain this data.
In 1.1 you use the ConfigurationSettings class
in 2.0 you utilise the System.ConfigurationManager and this supports the System.ConfigurationManager.ConnectionStrings for <ConnectionStrings> entries.

No comments:

Post a Comment