Page 1 of 1

SQLite detach database produces database is locked error

Posted: 18.10.2024, 18:28
by lfcap
Hello,
I use attached databases with SQLite on my projects and it works well with Zeosdb 7.0 and 7.1.
But it no longer works with Zeosdb 7.2 and 8.0.

My need is to open a "master" database and attach another detail database among several available. We open only one detail database at a time. It is closed to open another but without closing the "master" database or the datasets linked to it.
To close the detail database, we close all the datasets linked to this database and then use the DETACH DATABASE "detail" instruction.

The DETACH DATABASE instruction causes a locked database error if we have opened more than one table in the "master" database.

Attached is a test program source (include 2 files db3):
Project1_test_detach_db.zip
Use the Open, Attach and Detach buttons in order to get the error.
Note: Compiler is Delphi 10.3

Thank you for your help.

Re: SQLite detach database produces database is locked error

Posted: 20.11.2024, 10:38
by lfcap
Hello,
After several days of research, we found a workaround.
I don't know if it is sustainable but it currently works with ZeosDb V8.0.

Description:
The problem comes from the fact that some Datasets opened on database 1 also cause database 2 to be locked even though all Datasets in database 2 are closed.
The locking is due to the fact that the Dataset cursor remains active until all records are browsed.
The workaround consists of executing the FetchAll method on all Datasets still open in order to close the cursors.

See the source code of the attached example.
Project1_workaround_detach.zip