Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi . in DAL i have the below code . the error is "the name 'configurationManager' does not exist in current context".

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace DAL
{

    public class Class1
    {
        string connStr = ConfigurationManager.ConnectionStrings["myCon"].ToString();
       

    }
}



withal in 'web.config' i have:
XML
<add name="myCon" connectionString="Data Source=mydata;Initial Catalog=myDB;Integrated Security=false; User Id=sa; Password=123" providerName="System.Data.SqlClient" />


any help would be appreciate
Posted

you just have added namespace system.configuration which is not enough.
You have also to add the reference to the assembly System.Configuration.dll , by right-click-ing on the References tab, choose add reference and then find System.Configuration.
 
Share this answer
 
U have to use
C#
System.Configuration
namespace for that u have to add reference
C#
System.Configuration.dll 

and replace the
C#
string connStr = ConfigurationManager.ConnectionStrings["myCon"].ToString();

with
C#
string connStr = ConfigurationManager.ConnectionStrings["myCon"].ConnectionString

and let me know if its helps or not
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900