Search code examples
entity-frameworkms-accessconnection-string

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"


Solution

  • 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.