5

Throwing this up here since the author asks for help requests to go to StackOverflow.

Have an existing app in progress, originally wrote to SQL Server. Sadly now there is a very old Access Database that I must talk to. Trying to use JetEntityFramework to help me out so I don't need to make wholesale substitutions. Out of the gate, this exception I throw. I suspect a problem with web.config as the documentation for setting this up correctly is sparse.

Error

System.InvalidOperationException was unhandled by user code
HResult=-2146233079 Message=The 'Instance' member of the Entity Framework provider type 'JetEntityFrameworkProvider.JetProviderFactory, JetEntityFrameworkProvider, Version=1.2.4.0, Culture=neutral, PublicKeyToken=756cf6beb8fe7b41' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must inherit from this class and the 'Instance' member must return the singleton instance of the provider. This may be because the provider does not support Entity Framework 6 or later; see http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

Here is the relevant snippet of my web.config (was asked to change the actual name of the DBContext and MDB file)

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="JetEntityFrameworkProvider" type="JetEntityFrameworkProvider.JetProviderFactory, JetEntityFrameworkProvider"/>
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="MyDBContext" 
         connectionString="Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\MyAccessDB.MDB" 
         providerName="JetEntityFrameworkProvider.JetConnection" />
  </connectionStrings>
  <system.data>
    <DBProviderFactories>
      <remove invariant="JetEntityFrameworkProvider"/>
      <add invariant="JetEntityFrameworkProvider"
           name="Jet Entity Framework Provider"
           type="JetEntityFrameworkProvider.JetProviderFactory, JetEntityFrameworkProvider"/>
    </DBProviderFactories>
  </system.data>
Nkosi
  • 191,971
  • 29
  • 311
  • 378
JoeHz
  • 2,035
  • 1
  • 17
  • 27
  • Does the provider support Entity Framework 6 or later? which I assume is the version of EF that you are using – Nkosi Jan 01 '17 at 19:38
  • It says something about it supporting only code first. – Nkosi Jan 01 '17 at 19:45
  • Check codeplex documentation here https://jetentityframeworkprovider.codeplex.com/documentation – Nkosi Jan 01 '17 at 19:48
  • It's an existing app I'm using, so it's totally code-first :-) I'm also looking a the source code there and JetProviderServices.cs indeeds subclasses DbProviderServices (I clearly have checked out the documentation. It's where it suggests these stack overflow tags to get the author's attention) – JoeHz Jan 01 '17 at 19:51
  • But you mention that the old db already exists? which indicates db-first. – Nkosi Jan 01 '17 at 19:53
  • the old *app* exists, talking to an SQL Server version of this access database. The plan was to copy the data back to Access after the fact, but some changes now won't allow for that path. I absolutely have to talk to the Access database, but it's a Code-First implementation. I could likely have my code generate this database in Access if I got the Jet EntityFramework configured correctly. It's absolutely not a DB First implementation. Database-First means the EF generates your object model code for you from a database schema. Totally Not doing that. – JoeHz Jan 01 '17 at 19:56
  • Ok I understand what you mean. – Nkosi Jan 01 '17 at 20:01
  • Here is a though. Just watched the demos from the codeplex site and noticed that the provider name in your connection and the invariantName of the provider do not match like they do in the tutorials. change `JetEntityFrameworkProvider.JetConnection` to `JetEntityFrameworkProvider` and see if that makes a difference. You should take a look at the videos as well as I am also noticing some differences with the configuration there as apposed to what you have in your example – Nkosi Jan 01 '17 at 20:17
  • I'll give it a shot. There are a number of different things I've tried. JetConnection was something I saw there on another thread. Part of the video I feel I need to see was off the side of the author's screen. – JoeHz Jan 01 '17 at 20:25
  • No luck. FWIW, the class that does implement the class it is supposed to is JetProviderServices. I guess I need to find out where that needs to go in the web.config – JoeHz Jan 01 '17 at 20:31
  • was able to scrub the video to see what was off the side of the screen. saw the same JetProviderServices. check my answer below – Nkosi Jan 01 '17 at 20:33

1 Answers1

4

In your example the provider uses JetEntityFrameworkProvider.JetProviderFactory as its type. This caused the above exception because it does not inherit from System.Data.Entity.Core.Common.DbProviderServices. From the video tutorial and also from inspecting the source code JetEntityFrameworkProvider.JetProviderServices is the type needed for the provider.

Based on the tutorial from the project site, check the following configuration that was shown as an example.

  <connectionStrings>
    <add name="MyDBContext" 
         connectionString="Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\MyAccessDB.MDB" 
         providerName="JetEntityFrameworkProvider" />
  </connectionStrings>
 <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider 
        invariantName="JetEntityFrameworkProvider" 
        type="JetEntityFrameworkProvider.JetProviderServices, JetEntityFrameworkProvider"/>
    </providers>
  </entityFramework>
  <system.data>
    <DBProviderFactories>
      <remove invariant="JetEntityFrameworkProvider"/>
      <add 
        invariant="JetEntityFrameworkProvider"
        name="Jet Entity Framework Provider"
        description="Jet Entity Framework Provider"
        type="JetEntityFrameworkProvider.JetProviderFactory, JetEntityFrameworkProvider"/>
    </DBProviderFactories>
  </system.data>
Nkosi
  • 191,971
  • 29
  • 311
  • 378
  • Yeah I found it at the same time doing it the way I mentioned above. Next error to be asked about in a few moments. lol – JoeHz Jan 01 '17 at 20:36