1

I already added the reference System.Configuration and still, I get recieving that error. I am using VS2010. Here is the code

<configuration>
<connectionStrings>
    <add name="MESConnection" connectionString="Server=.\SQLEXPRESS;Database=MES;Trusted_Connection=true"/>
</connectionStrings>
<system.web>
    <compilation debug="true" targetFramework="4.0">
        <assemblies>
            <add assembly="System.Configuration.Install, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation>
</system.web>

and the code behind:

private static string _connStr = ConfigurationManager.ConnectionStrings["MESConnection"].ConnectionString;

Any ideas?

Yanker
  • 292
  • 5
  • 10
  • 25

2 Answers2

3

Add a using statement at the top of your cs code file:

using System.Configuration;

Or fully qualify the reference:

private static string _connStr = 
    System.Configuration.ConfigurationManager.ConnectionStrings["MESConnection"].ConnectionString;

EDIT

I see you haven't in fact referenced the correct assembly. You need to reference System.Configuration.dll not System.Configuration.Install.dll

Also the usual way to reference a .NET assembly in Visual Studio is to right-click on the References node in Solution Explorer and choose Add Reference...

enter image description here

hollystyles
  • 4,979
  • 2
  • 36
  • 38
  • I already added the using statement. And tried to add that line also. IT DOES NOT RESPOND – Yanker Nov 05 '12 at 12:53
  • lol god forbid. I never shout on people, only on computers :) Thank you HollyStyles. It seems that I added the reference in the wrong place. those noobs... – Yanker Nov 05 '12 at 13:50
-1
  1. Go to your solution explorer on the right-hand side
  2. Right click on references
  3. Select add.

Now you can add the configuration library and just access using its namespace

John M. Wright
  • 4,477
  • 1
  • 43
  • 61
teyim
  • 1
  • 1