user1312412
user1312412

Reputation: 203

The name 'ConfigurationManager' does not exist in the current context

Hi every one I am getting the following error: "The name 'ConfigurationManager' does not exist in the current context"

// namespaces
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;

namespace Database1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public static string GetConnectionString(string strConnection)
        {
            //variable to hold our connection string for returning it

            string strReturn = "";
            //check to see if the user provided a connection string name
            //this is for if your application has more than one connection string

            if (!string.IsNullOrEmpty(strConnection)) //a connection string name was        
            {
                //get the connection string by the name provided
                strReturn = ConfigurationManager.ConnectionStrings[strConnection].ConnectionString;

            }
            else //no connection string name was provided
            {
                //get the default connection string
                strReturn = ConfigurationManager.ConnectionStrings["YourConnectionName"].ConnectionString;
            }
            //return the connection string to the calling method
            return strReturn;
        }

    }
}

Upvotes: 3

Views: 16648

Answers (5)

Oloruntobi Junaid
Oloruntobi Junaid

Reputation: 11

I ran into same issue using .Net Core, but using .NET Running Install-Package System.Configuration.ConfigurationManager in Package manager solved it for me.

Upvotes: 1

Nidhi Bhatt
Nidhi Bhatt

Reputation: 31

This is the path:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Configuration.dll

also you can add reference to the :System:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Configuration.Install.dll

(hope it helps :))

Upvotes: 3

Lex Li
Lex Li

Reputation: 63289

Which version of .NET Framework and Visual Studio are you using?

ConfigurationManager is only available in .NET 2 and above. If you are using .NET Framework 1.x and Visual Studio 2002/2003, you won't be able to use this class at all.

http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx

Click "Other versions" link in the top of this page and you will see all versions it supports.

Upvotes: 1

Pete
Pete

Reputation: 635

You have to add reference to System.Configuration.dll

When you right click and click on the Add reference button

Click .Net tab in the open popup

There you should be able to locate the System.Configuration.dll file

Upvotes: 6

Joshua
Joshua

Reputation: 4159

Have you added a reference to System.Configuration.dll?

Upvotes: 12

Related Questions