Pergunta

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?

Foi útil?

Solução

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

Outras dicas

  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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top