Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLite database file locked and not getting released when database is closed #1648

Open
snydesc opened this issue Dec 30, 2024 · 0 comments
Open

Comments

@snydesc
Copy link

snydesc commented Dec 30, 2024

This started happening in version 9.0.0 of EFCore.BulkExtensions.Sqlite.

Calling

using (var transaction = context.Database.BeginTransaction())
{
   BulkConfig mDefaultBulkConfig = new BulkConfig() { BatchSize = 250000, SqlBulkCopyOptions = EFCore.BulkExtensions.SqlBulkCopyOptions.Default };
   await context.BulkInsertAsync(listOfEntries, mDefaultBulkConfig, null, null, cancellationToken).ConfigureAwait(false);
   await transaction.CommitAsync(cancellationToken).ConfigureAwait(false);
}

SqliteConnection.ClearAllPools();
await context.Database.CloseConnectionAsync();

Keeps a lock on the sqlite database file. I try to zip up the database file and get an IOException ("The process cannot access the file XXX because it is being used by another process").

Same exact code runs fine under 8.0.2 of bulk extensions (I haven't tested the versions between 8.0.2 and 9.0.0).
Replacing BulkInsertAsync with context.AddRangeAsync() and context.SaveChangedAsync() fixes the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant