The problem
When i try to scaffold the nordhwind.accdb i get a COM Exception
In VSCode Powershell Terminal:
dotnet ef dbcontext scaffold "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=<PATH>\northwind.accdb" EntityFrameworkCore.Jet -o Models
In Visual Studio 2022 Paket Manager Console:
Scaffold-DbContext -Connection "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=<PATH>\northwind.accdb" -Provider EntityFrameworkCore.Jet
The exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.Runtime.InteropServices.COMException (0x800A0CB3): Das Objekt oder der Provider kann den angeforderten Vorgang nicht ausführen.
--- End of inner exception stack trace ---
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at EntityFrameworkCore.Jet.Data.ComObject.TryGetMember(GetMemberBinder binder, Object& result)
at CallSite.Target(Closure, CallSite, Object)
at EntityFrameworkCore.Jet.Data.AdoxSchema.GetColumns()
at EntityFrameworkCore.Jet.Data.PreciseSchema.GetColumns()
at EntityFrameworkCore.Jet.Data.JetStoreSchemaDefinition.JetInformationSchema.GetColumns(JetConnection connection)
at EntityFrameworkCore.Jet.Data.JetStoreSchemaDefinition.JetInformationSchema.GetDbDataReaderFromSimpleStatement(JetCommand command)
at EntityFrameworkCore.Jet.Data.JetStoreSchemaDefinition.JetInformationSchema.TryGetDataReaderFromInformationSchemaCommand(JetCommand command, DbDataReader& dataReader)
at EntityFrameworkCore.Jet.Data.JetCommand.ExecuteDbDataReaderCore(CommandBehavior behavior)
at EntityFrameworkCore.Jet.Data.JetCommand.ExecuteDbDataReader(CommandBehavior behavior)
at EntityFrameworkCore.Jet.Scaffolding.Internal.JetDatabaseModelFactory.GetColumns(DbConnection connection, IReadOnlyList`1 tables)
at EntityFrameworkCore.Jet.Scaffolding.Internal.JetDatabaseModelFactory.GetTables(DbConnection connection, Func`3 filter)
oryOptions options)
at EntityFrameworkCore.Jet.Scaffolding.Internal.JetDatabaseModelFactory.Create(String connectionString, DatabaseModelFactoryOptions options)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
What i have done so far
I'm currently testing to connect to an existing access mdb using the EntityFrameworkCore.Jet provider. For test purposes i downloaded the latest northwind.accdb from here: https://learn.microsoft.com/de-de/dotnet/framework/data/adonet/sql/linq/downloading-sample-databases
I opened the DB in Access and in Visual Studio 2022 (Server Explorer) to ensure it is accessible. Then i created a simple project with a DbContext:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EntityFrameworkCore.Jet" Version="7.0.3" />
<PackageReference Include="EntityFrameworkCore.Jet.Data" Version="7.0.3" />
<PackageReference Include="EntityFrameworkCore.Jet.Odbc" Version="7.0.3" />
<PackageReference Include="EntityFrameworkCore.Jet.OleDb" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.15" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.15">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Data.OleDb" Version="7.0.0" />
</ItemGroup>
</Project>
public class JetTestContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseJet(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=<PATH>\northwind.accdb;");
}
}
I also made a little unit test to ensure a can instantiate the JetTestContext
But this should not influence the scaffolding in any way. I already searched but the only solutions i found are missing or wrong OLEDB drivers and i don't think thats my problem here as i can access the northwinddb, have Access installed and can browse the DB with the VS Server Explorer. What am i missing here?
EDIT The Access Database Engine 2016 is also installed and the Unit Test is successful:
public void JetConnection()
{
using (JetTestContext context = new JetTestContext())
{
context.Database.OpenConnection();
context.Database.CloseConnection();
Assert.IsTrue(context.Database.CanConnect());
}
}