22

I'm constructing a DbContext from an SqlConnection. When I use it, I receive the following error:

The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' for the 'System.Data.SqlClient' ADO.NET provider could not be loaded.

I'm using 6.0.0-alpha2-11210.

I found that weird since I have a reference toward Entity.SqlServer and that I managed to 'fix it' by putting the following line of code before a query:

var patch_only = System.Data.Entity.SqlServer.SqlProviderServices.Instance;

Is it a bug of the alpha version?

1
  • How are you running? If you're deploying, then EntityFramework.SqlServer.dll might be getting skipped since nothing actually has a hard dependency on it. If this is the case, please file a bug.
    – bricelam
    Feb 22, 2013 at 0:44

8 Answers 8

38

What you did creates a reference to EntityFramework.SqlServer.dll. It ensures that this assembly gets copied over to the bin folder of projects using you data access assembly.

You can do the same by adding something like the following somewhere in your data access assembly:

Type _Hack = typeof(System.Data.Entity.SqlServer.SqlProviderServices)
1
  • Ugly hack...but it immediately solved my problem. C'mon Microsoft!?
    – Tsar Bomba
    May 1, 2016 at 21:03
13

I hope I am not late. I am using ASP.NET MVC 4 and Entity Framework 6 alpha 3 and ran into a similar problem.

I have multiple projects in my solution. The 2 main projects are:

MyProject.Infrastructure.EntityFramework
MyProject.Web

In the first project I would set up all my repositories, DbContext, etc etc. In this project I have 2 references:

EntityFramework
EntityFramework.SqlServer

The second project is my website. It uses the repositories in the first project to return my data. For example:

private readonly IMyRepository myRepository;

public MyController(IMyRepository myRepository)
{
     this.myRepository = myRepository;
}

public ActionResult Details(int id)
{
     MyObject myObject = myRepository.FindById(id);

     return View();
}

This is where I had my issues, calling FindById.

All that I did was to add the following reference to my website:

EntityFramework.SqlServer

In my web.config:

<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=b77a5c561934e089" requirePermission="false" />
</configSections>

And beneath the closing system.webServer tag:

<entityFramework>
     <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
               <parameter value="v11.0" />
          </parameters>
     </defaultConnectionFactory>
</entityFramework>

I hope this will help.

3
  • What does your connection string look like? I'm having the same issue still even after applying your web.config settings. My connection string is as follows: <add name="NorthwindContext" connectionString="Data Source=|DataDirectory|\Northwind.sdf;Persist Security Info=False;" providerName="System.Data.SqlServerCe.4.0" /> Now I'm getting this error: --------------------------- An error has occurred. No Entity Framework provider found for 'System.Data.SqlServerCe.4.0' ADO.NET provider. Make sure the provider is registered in the 'entityFramework' section of the application config file.
    – LeLong37
    Jul 29, 2013 at 22:49
  • 2
    This is not an answer why this reference is required or whether it is a bug or not. The workaround described is obvious and hence not useful. Oct 8, 2013 at 13:49
  • no, this didn´t work for me, you should go for the other answers. Feb 5, 2014 at 17:38
10

The problem is the "EntityFramework.SqlServer" reference.

In my project, when I added Entity Framework 6.0.1 by using NuGet in data access layer, I got the same error in the client side since client side doesn't have that reference.

So, I solved the issue by adding that reference into the client side, too.

1
  • 1
    A wise man once told me "know why you put the eggs in the cake"... The Hack works fine in Debug mode but the compiler will remove the useless (unreferenced) line if compiled in Release, and subsequently the EntityFramework.SqlServer.dll would still be missing from the project's output. Agreed, the real answer is to make sure the dll makes it to where it needs to be.
    – MoMo
    Feb 26, 2014 at 22:06
1

I am using EF 4 and EF 6 two different projects in the same solution.

After using NuGet for EF 6.0 all references to EF 4 where removed in my test Project. I had to remove EF6 from the project again and added references to System.Data.Entity for EF4.

To access data thru EF6 in the test Project I had to manually reference the EntityFramework.SqlServer.dll (4.5) and used the hack (above) recommendation.

There was no need to do any alternations in the app.config of my test project.

no

 <section name="entityFramework" ...

and no

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> ...
0

@LeLong37

I had exactly the same error like you: "... No Entity Framework provider found for 'System.Data.SqlServerCe.4.0' ADO.NET provider..."

I solved it by adding a reference to "EntityFramework.SqlServerCompact" from directory "packages\EntityFramework.SqlServerCompact.6.0.0-rc1\lib\net40"

hope this helps

0

I added a screencast at Youtube describing this and the solution in about 6 minutes. I did this because the solution provided by Fabrice is not working when you work with Team Build which runs into the same issue.

0

If you are having problems with a brand new MVC site from the template: 1) Uninstall Microsoft.ASPNet.Identity.EntityFramework (It will ask you if you want to uninstall Entity Framework - go ahead and do that.) 2) Install Entity Framework 3) Reinstall Microsoft.ASPNET.Identity.EntityFramework

Should be working now.

-2

I solved the problem by copying the two files

EntityFramework.SqlServer.dll
EntityFramework.SqlServer.xml

to the /bin.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.