Getting error 'Database source is locked.' when trying to detach a database

Discussion of open issues, suggestions and bugs regarding LiteDAC (SQLite Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
jodyatfsec
Posts: 8
Joined: Wed 06 Nov 2013 13:41

Getting error 'Database source is locked.' when trying to detach a database

Post by jodyatfsec » Fri 12 Aug 2016 14:02

I am getting an error 'Database source is locked.' when I try to detach a database which I previously attached using the name 'source'.

I have 2 SQLITE databases. I want to copy data from one database to the other database. I want it to run quickly. Here is code for the procedure that attaches or detaches the database. The parameter 'myAction' is either 'ATTACH" or 'DETACH'. The first time I do an attach followed by a detach, it runs. The second time, the attach runs OK but the detach gets the error.

procedure TBuildingComponent.AttachDetachDatabaseSourceForGEN(myAction: string);
begin
//Cannot ATTACH if in transaction
if Search.USAGENConnection.InTransaction then
Search.USAGENConnection.Commit;
if Splash.USARESConnection.InTransaction then
Splash.USARESConnection.Commit;
//try inactivating stuff that might leave the database open
if Search.resProjTblLite.active then Search.resProjTblLite.active := false;
if Search.resTblLite.active then Search.resTblLite.active := false;
Search.SqliteProject_search.active := false;

if (myAction = 'ATTACH') then
begin
Search.USAGENConnection.ExecSQL('attach "' + Global.SQLitePath + 'USARES.sqlite" as source');
end;
if (myAction = 'DETACH') then
begin
Splash.USARESConnection.DisConnect; //this is at Global.SQLitePath + 'USARES.sqlite"
Splash.USARESConnection.close;
Search.USAGENConnection.ExecSQL('detach DATABASE source');
Splash.USARESConnection.connect;
end;

end;

I am using Delphi XE5. Windows 7. LiteDac Professional 2.4.13.
i basically need a quick way to move data from one database to another database.

MaximG
Devart Team
Posts: 1024
Joined: Mon 06 Jul 2015 11:34

Re: Getting error 'Database source is locked.' when trying to detach a database

Post by MaximG » Mon 15 Aug 2016 09:23

Unfortunately, we couldn't reproduce the problem using the provided code. For the following investigation, please send us a small example that demonstrates the problem, including a test DB. You can send to maximg*devart*com

Post Reply