4

I have a solution with 2 projects: asp app and console app. In my web.config on my asp project I have this: <connectionStrings> <add name="con" connectionString="Data Source=PC-Flo\SQLExpress2008;Initial Catalog=test;Persist Security Info=True;User ID=lol;Password=lolation" providerName="System.Data.SqlClient" /> </connectionStrings>

and my connection works.

Now I want to connect with my console app so in my App.config I put the same thing but I have this exception:

The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception

Thanks for your help.

The App.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
    <add name="con" connectionString="Data Source=PC-Flo\SQLExpress2008;Initial Catalog=test;Persist Security Info=True;User ID=lol;Password=lolation" providerName="System.Data.SqlClient" />
</connectionStrings>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=" requirePermission="false" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
5
  • 1
    post your entire app.config file content Commented Jan 4, 2015 at 19:15
  • What is the EF version for both projects? Commented Jan 4, 2015 at 20:01
  • Oh, and please have a look here: stackoverflow.com/questions/17585611/… Commented Jan 4, 2015 at 20:02
  • The version of Entity Framework for both projects is 6.0.0.0 Commented Jan 4, 2015 at 20:04
  • You should take a look this question: stackoverflow.com/questions/19801125/… Commented Jan 4, 2015 at 20:15

1 Answer 1

1

I delete all my file and just put this inside

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>

    </configSections>
    <connectionStrings>
        <add name="con" connectionString="Data Source=PC-Flo\SQLExpress2008;Initial   Catalog=test;Persist Security Info=True;User ID=lol;Password=lolation" providerName="System.Data.SqlClient" />
    </connectionStrings>

</configuration>

and finally it works. Thanks for your help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.