Connecting to SQL Server with EF6

entity-framework entity-framework-6


Up to EF5, in order to connect to SQL Server 2012, all I needed to to is specify a connection string that looks something like this:

Data Source=.\SqlExpress;Initial Catalog=MyDatabase;Integrated security=True;MultipleActiveResultSets=True

This method is not working with EF6, giving exception

No Entity Framework provider found for 'System.Data.Odbc' ADO.NET provider. Make sure the provider is registered in the 'entityFramework' section of the application config file

I am not using app.config file at all, I am passing above connection string to MyContext constructor. WHy is it trying to use Odbc provider at all, and instead not using System.Data.SqlClient?

What needs to be done to connect to SQL Server with EF6 code-first? I made sure that EntityFramework.dll and EntityFramework.SqlServer.dll are both available in Application folder. I have even added EF6 nuget package v6.0.0.1 in WPF project, although it does not use EF library directly, and making sure that automatically created App.Config file (by nuget) is copied to Application (Debug) folder - still no success.

I have also tried to setprovider manually in code:

public class OeeCoachConfiguration : DbConfiguration
    public OeeCoachConfiguration()

Still no success. My Project structure is as follows (simplified):

WPF project - does not have reference to EF (also tried adding EF reference)

ViewModel class library - does not have reference to EF

Model class library - has reference to EF library (both dlls)

Data class library - has reference to UI library (both dlls).

I am using CodeFirst approach, and this setup works without any problem with EF5. Any help is greatly appreciated.

10/24/2013 11:37:26 PM

Accepted Answer

For me this error was resolved by removing the Glimpse.ADO package

Edit December 20, 2013 I believe the Glimpse.ADO package now supports EF6, but I have not tested it.

12/20/2013 4:28:37 PM

Popular Answer

I had the same problem and I eventually tried the following and it worked (keeping Glimpse EF5 & Glimpse ADO packages)

In the web.config I added a copy of the existing provider line but changed it's invariantName to "System.Data.Odbc".

    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
        <parameter value="v11.0" />
      <provider invariantName="System.Data.Odbc" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />

Hope that this helps.


Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow