This project has moved. For the latest updates, please go here.

Correct Connection String

Apr 11, 2016 at 2:21 PM
Hi There,
I'm struggling to get the NuGet version of the Jet Entity Framework Provider to see my old Access database. What should a correctly configured connection string look like for an Access MDB files being accessed using this framework provider?

If I use my standard string...

<add name="MOPSDataModel" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Temp\mopsdata.mdb" providerName="System.Data.OleDb" />

...I get...

The server encountered an error processing the request. The exception message is 'A null was returned after calling the 'get_ProviderFactory' method on a store provider instance of type 'System.Data.OleDb.OleDbConnection'. The store provider might not be functioning correctly.'.


If I invent a connection string based on what I see for a working SQL-based EF provider...

<add name="MOPSDataModel" connectionString="metadata=res:///MOPSDataModel.csdl|res:///MOPSDataModel.ssdl|res://*/MOPSDataModel.msl;provider=Microsoft.Jet.OLEDB.4.0;provider connection string="Data Source=C:\Temp\mopsdata.mdb"" providerName="System.Data.EntityClient" />

...I get...

The server encountered an error processing the request. The exception message is 'The ADO.NET provider with invariant name 'Microsoft.Jet.OLEDB.4.0' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.'

What's the correct syntax?

Cheers
Jason.
Coordinator
Apr 12, 2016 at 12:26 PM
Edited Apr 12, 2016 at 12:28 PM
The right provider name is JetEntityFrameworkProvider.JetConnection

You could start trying connect without using app.config (instantiating DbContext with an open connection)


Check also that app.config is ok
  <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>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="JetEntityFrameworkProvider" type="JetEntityFrameworkProvider.JetProviderServices, JetEntityFrameworkProvider" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
PS: If you post the question on stack overflow could be that someone else helps you (and me :) ).