-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
SqliteConnection.Dispose does not release .db file on Windows (6.0 rc1 ->) #26369
Comments
This is by design - connection pooling was implemented in version 6.0 of the Sqlite provider, which keeps connections open so they can be recycled for better performance (see docs). You can use the |
Thanks a lot. I ran into a lot of issues with too many attached databases, etc, for my unit tests, so I had to resort to I'll look into it later, but turning off pooling makes it work as before, at least, Thanks! |
Just a follow-up question: Since the files were not locked on Linux, does that mean that connection pooling is not working in the same way on Linux, or just that file locking works differently on Linux fundamentally? |
Re-opening to discuss with team the "SQLite Error 1: 'too many attached databases - max 10.'" error. Not sure how connection pooling would result in this. /cc @bricelam |
The latter - the moment you open a file under Windows (for writing IIRC), it is locked and other processes can no longer open it. Linux does not do that by default. |
Are you using the Sqlite ATTACH command in your application or tests? If so, can you please make sure you do DETACH as well? Pooling makes this necessary since connections get reused, effectively manifesting the attach "leak". |
Hi again. Yes, I was indeed using "ATTACH", and was not "DETACH"-ing well enough. I'm developing a SQL took supporting many database types (SQL Server, PostgreSQL, MariaDB, etc), and want to keep things as similar as possible between the database types. The "CREATE DATABASE" and "DROP DATABASE" equivalents in Sqlite were a bit difficult to land on, but now I landed on:
I've removed the usage of attach and detach, as they weren't really necessary for my use case. Thanks for taking the time to answer, even though the error/misunderstanding was on my part! |
@erikbra Thanks for gettin back to us. |
There seems to be a bug in Microsoft.Data.Sqlite, v 6.0, from rc1 onwards, which makes the database file remain locked after the SqliteConnection is closed, but only on Windows. It works up until preview7 (of the versions published on Nuget.org).
Repo with small repro can be found here: https://github.com/erikbra/Microsoft.Data.Sqlite-dispose-bug
It fails with the following stacktrace:
Include version information
Microsoft.Data.Sqlite version: 6.0.0-rc.1.21452.10 and 6.0.0-rc.2.21480.5
Target framework: .NET 6.0rc2 (6.0.100-rc.2.21505.57)
Operating system: Windows 11, build 22478.1000), but probably on earlier versions too
The text was updated successfully, but these errors were encountered: