Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Cannot seem to use ConfigurationManager class

Posted on 2007-12-05
2
Medium Priority
?
4,119 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

721 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