Reputation: 154
I am having difficulty with a Firedac
Sqlite
Database in Delphi 10.3.1
I am using the Dbnavigator
and DbGrid to enter new records directly into the selected table. Each time I try and post the new record, I get a Firedac error message 'Error: database is locked'
This also happens when I try to delete a record. This only happens when the IDE is running. I have read several posts across many forums highlighting the same issue. I have tried altering the Locking Mode settings, but the problem still persists. It is quite frustrating to have to leave the IDE, run the executable, test and re-enter the IDE to debug.
Any help would be much appreciated.
Upvotes: 2
Views: 4978
Reputation: 21
I had the same problem and it was very stubborn! Delphi 11 Update 3 (CE) with the CE patch in a windows 32 bit application. Basically I could access my sqllite database at design time, but at run time I just could not access it at all. Always raised the exception that the database was locked. I closed all connections and data access components on the form but just could not shake the error. Finally, quite by chance I came upon this:
https://docwiki.embarcadero.com/RADStudio/Sydney/en/Connect_to_SQLite_database_(FireDAC)
Partway down the page it said the sqllite dll does not ship with windows versions of delphi. I followed the link and downloaded the 32 bit pre-compiled version and placed the unzipped files in my program's executable file directory. That solved the problem the next time I compiled.
I just wish there was an idiots guide to using sqllite with delphi that covered all the basics including how to create databases and tables and how to get the system to work in the IDE. It was just so much easier in the days of the BDE and database explorer!
Also: By chance I found sqllite studio which does make creating databases and tables quite easy, but I might be missing some delphi features there.
Hope this helps someone.
Upvotes: 2
Reputation: 11
Inside my application I have a class that is responsible for returning the connection, I implemented this code snippet and solved this problem
function TModelConnection.Connection: TFDConnection;
begin
System.TMonitor.Enter(FConnection);
try
Result := FConnection;
finally
System.TMonitor.Exit(FConnection);
end;
end;
Upvotes: 1
Reputation: 30715
The "database is locked" message arises if you have the Sqlite database, or the table within it, open in the IDE; that places a lock on the database which your app detects and complains about at run-time.
The solution is simple: make sure that the table is not open in the IDE and that the FireDAC connection to it is not active either.
Upvotes: 5