470,591 Members | 2,089 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

Reading a connection string from the config file

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

Nov 19 '05 #1
0 1315

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Jon Davis | last post: by
2 posts views Thread by news.microsoft.com | last post: by
9 posts views Thread by =?Utf-8?B?Vmlua2k=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.