Getting Lock State

Discussion of open issues, suggestions and bugs regarding LiteDAC (SQLite Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
davor.TCS
Posts: 29
Joined: Thu 05 Apr 2012 22:10
Contact:

Getting Lock State

Post by davor.TCS » Thu 28 Feb 2019 08:11

I have two application's that use same db file. 1st application is service and it always writes data in db file. Second application is GUI in which you set initial values in same db file. However when i try to write to db file I get Error 5 (database is locked).
1. Is there any way to share file between two applications?
2 How can I detect who has lock write on db file?

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

Re: Getting Lock State

Post by MaximG » Fri 05 Apr 2019 08:42

1. When the same SQLite file is used by several applications, first of all, you need to follow the description provided at the project web site: https://www.sqlite.org/lockingv3.html
The occurrence of the SQLITE_BUSY error is always related to the competing access to DB since SQLite supports only one writer at a time. Thus, normally you need to process this error in the code of the application being developed according to the business logic of its work. To minimize the number of SQLITE_BUSY errors, you can try using the WAL (sqlite.org/wal.html) mode. To enable this mode in LiteDAC, you can do the following:

Code: Select all

LiteConnection.ExecSQL('PRAGMA journal_mode=WAL');
Besides, you can set the suggested wait time out with the BusyTimeout option: https://www.devart.com/litedac/docs/dev ... imeout.htm
2. Our components do not provide access to the information you inquired about.

davor.TCS
Posts: 29
Joined: Thu 05 Apr 2012 22:10
Contact:

Re: Getting Lock State

Post by davor.TCS » Sun 07 Apr 2019 06:18

Busy timeout solved the problem. I did not mention, this application is basically in one exe file. This exe file can be installed as service (then it collects data and writes it in DB file) and as GUI application (then you can set options and view data). Problem was when both try to write data at the same time.
Also, service is behaving very strangely.
At Windows XP on starting computer Service starts (I can stop it, and start it, no problem).
But on OS > Windows 7 Service will not start on starting computer (I can stop it, and start it, no problem)?
I know this is of topic, but if you have any suggestion, please share.

Thank you.

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

Re: Getting Lock State

Post by MaximG » Wed 10 Apr 2019 10:09

The described behavior is not related to the behavior of our product. The solution of this issue can be found by using specialized forums.

davor.TCS
Posts: 29
Joined: Thu 05 Apr 2012 22:10
Contact:

Re: Getting Lock State

Post by davor.TCS » Thu 11 Apr 2019 10:07

True. Thanks.

Post Reply