Reading a connection string from the config file


C

Chris Durkin

What is the "correct" .NET 2.0 way to do this from within a class
library?

For example, say I have a connection string in app.config or web.config
added using the VS2005 IDE, like so:

<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="ProjectName.My.MySettings.Connect1"
connectionString="Data Source=x;Initial
Catalog=y;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>

How do I get the above setting in a way that works from both WinForms
and ASP.NET applications? The class is in a DLL which could be called
from either type of client.

The Patterns and Practices Enterprise Library (November CTP for .NET
2.0) uses ConfigurationManager to do it, but MSDN Help says this:

"Using WebConfigurationManager is the preferred way to work with
configuration files related to Web applications; all other methods are
deprecated. For client applications, we recommend that you use the
ConfigurationManager."


If Enterprise Library is an implementation of Microsoft best practices,
then why is it using a deprecated method for reading configuration?



Thanks,
Chris
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top