Solved

Cannot seem to use ConfigurationManager class

Posted on 2007-12-05
2
4,109 Views
Last Modified: 2013-12-16
Hi Experts,
I don't understand why i get this error. Checking the MSDN documentation, it is supposed to work in .NET 3.5:
http://msdn2.microsoft.com/en-us/library/system.configuration.connectionstringssection(VS.90).aspx

Even if i have the using System.Configuration; namespace, it still gives me the error. After doing a bit of research, i found some solutions where others had to manually add to the references of the project to System.Configuration DLL. (In the menubar at the top select Project | Add Referemce, then scroll down (in the .NET tab) to System.Configuration and double click it.).

I can do that and it will compile, the only problem i find is that the DLL i reference is associated with the framework 2.0. Will that create a problem knowing that i work on 3.5 for this project?
using System;

using System.Data;

using System.Data.SqlClient;

using System.Collections.Generic;

using System.Text;

using System.Configuration;
 

namespace ZoafabWin.Business

{

        private SqlConnection GetConnection()

        {

            return (new SqlConnection(ConfigurationManager.ConnectionStrings["zoafab2005ConnectionString"].ConnectionString));            

        }

    }

}

Open in new window

0
Comment
Question by:vortex350
2 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20413622
The System.Configuration.dll reference is not normally added to the project, so you need to do that before using System.Configuration.

Bob
0
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 250 total points
ID: 20413683
You always add references manually. That is the normal way of doing it, and the way that everybody adds references.

The using directive only specifies where the compiler looks for identifiers, it doesn't add any references.

There are some classes in the System.Configuration namespace in the mscorlib.dll, so they are always available, that's why it's possible to specify a usinbg directive for that namespace without a reference to the System.Configuration.dll library. The ConfigurationManager class is in the System.Configuration.dll library, so you have to add a reference to the library to have access to that class.

From what I can tell, there is no new version of System.Configuration.dll in framework 3.5, so it would be normal that the latest version would be 2. Framework 2.0 completely replaced framework 1.1, but framework 3.0 and 3.5 build incrementally on framewok 2.0.

http://shailkpatel.blogspot.com/2007/06/new-stuff-in-net-framework-35.html
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now