Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework with Microsoft Access

I use .accdb file. I created class

using System.Data.Entity;

    class MSADbContext:DbContext
    {
        public DbSet<Product> Products { get; set; }
    }

and add connectionString

<add name="MSADbContext" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\SportsStore.accdb" providerName="System.Data.OleDb"/>

After first query to DB I get the ProviderIncompatibleException: "calling "get_ProviderFactory" in repository typeOf "System.Data.OleDb.OleDbConnection" returns null"

like image 533
Stalli Avatar asked Aug 25 '13 15:08

Stalli


People also ask

Is Microsoft Access being phased out?

Is Microsoft Access still available? Yes! MS Access is still included in all business plans with Office 365. Access is a proven product that has been around for over 25 years and is the most widely used desktop, team and small/medium sized business database product.

What database does Entity Framework support?

EF Core works with many databases, including SQL Database (on-premises and Azure), SQLite, MySQL, PostgreSQL, and Azure Cosmos DB.

Is Entity Framework a data access layer?

Entity Framework is a data access layer. Specifically it's an Object Relational Mapper.


2 Answers

Your connection-string would be for an .mdb (Access 2003-) file. Check connection strings here

You need the ACE OLEDB provider. Standard Security:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;
Persist Security Info=False;

However, read this thread first:

Entity Framework does not support OLEDB connections, so your connection string will not work. It is practically impossible to get Entity Framework to collaborate with MS Access.

practically impossible is very compelling.

like image 191
Andy G Avatar answered Nov 10 '22 02:11

Andy G


OLEDB cannot support entity framework because entity framework needs that the entity framework provider generates the right queries for the specific database (while OLEDB is general DB access). You need a specific provider for Microsoft Access.

You can find a Microsoft Access Entity Framework Provider here https://jetentityframeworkprovider.codeplex.com/

EDIT
The Access EF provider is now hosted on GitHub
https://github.com/bubibubi/JetEntityFrameworkProvider

like image 26
bubi Avatar answered Nov 10 '22 03:11

bubi