How to set connection string for Entity Framework in console application
I have a solution with two projects, an asp app and a console app. In my web.config in my asp project I have the following:
<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 to my console app, so in my App.config I put the same, but I have this exception:
Type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception
Thank you for your help.
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>
+3
source to share
1 answer
I will delete my entire file and just put it 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.
0
source to share