EntityFrameworkCore.Jet icon indicating copy to clipboard operation
EntityFrameworkCore.Jet copied to clipboard

[ .net 5 ] : EnsureCreated always use ODBC

Open nicovil opened this issue 2 years ago • 4 comments

When executing ~~Migrate or MigrateAsync~~ EnsureCreated and EnsureCreatedAsync, it doesn't matter which connection string we use, the provider will always use ODBC.

In my case, I'm working with OLEDB and I want EnsureCreated to use OLEDB too, the reason is that I'm using some datatypes that doesn't works well with ODBC but everything works perfectly with OLEDB.

Not 100% sure, but looks like the JetDatabaseCreator invoke the CreateEmptyConnection method which for some reason retrieves ODBC by default.

As extra information, if you use Migrate and MigrateAsync, it uses OLEDB and migration just creates the database correctly.

nicovil avatar Mar 10 '22 17:03 nicovil

For more information, I'm using this workaround to create the database when using JET provider:

var databaseCreator = JetDatabaseCreator.CreateInstance(SchemaProviderType.Adox);
databaseCreator.CreateDatabase(theConnectionString);

This one works and creates the empty database, so later I can apply the Migration with Context.Database.Migrate() without any problem.

nicovil avatar Mar 10 '22 18:03 nicovil

@nicovil Sorry can you clarify a bit, since the following two statements seem contradict each other:

When executing Migrate or MigrateAsync, it doesn't matter which connection string we use, the provider will always use ODBC. [...] As extra information, if you use Migrate and MigrateAsync, it uses OLEDB and migration just creates the database correctly.

Thanks!

lauxjpn avatar May 13 '22 15:05 lauxjpn

Hi @lauxjpn.

Sorry for the confusion, what's wrong is the first sentence.

Where it says: When executing Migrate or MigrateAsync, it doesn't matter which connection string we use, the provider will always use ODBC.

It should say: When executing EnsureCreated and EnsureCreatedAsync, it doesn't matter which connection string we use, the provider will always use ODBC.

As I mention in a latter comment, by debugging Jet provider code I found a workaround to create the empty database by using:

var databaseCreator = JetDatabaseCreator.CreateInstance(SchemaProviderType.Adox);
databaseCreator.CreateDatabase(theConnectionString);

Sorry for my error.

nicovil avatar May 13 '22 16:05 nicovil

@nicovil Thanks, got it now! I'll take a look at this.

lauxjpn avatar May 13 '22 20:05 lauxjpn

Fixed as part of #135

ChrisJollyAU avatar Apr 01 '23 14:04 ChrisJollyAU