Recent

Author Topic: SQLite3 "database is locked"  (Read 42548 times)

Lacak2

  • Guest
SQLite3 "database is locked"
« on: May 24, 2010, 05:26:51 am »
When I run same application more than once on one computer (or from Windows network share from more computers) simultaneously, then when I try update and commit changes in one instance of application, I get error "database is locked" (SQLITE_BUSY). How to avoid this ?
 (see also http://www.sqlite.org/faq.html#q5)
I use sqldb (TSQLQuery+TSQLite3Connection)
« Last Edit: May 24, 2010, 05:55:16 am by Lacak2 »

stonefull

  • Jr. Member
  • **
  • Posts: 54
Re: SQLite3 "database is locked"
« Reply #1 on: May 24, 2010, 06:49:26 am »
the FAQ answers your question. I think you should use another database.

Batuhan

  • New Member
  • *
  • Posts: 14
Re: SQLite3 "database is locked"
« Reply #2 on: May 24, 2010, 01:01:16 pm »
Hi! check this link, (its user comment)

http://www.php.net/manual/en/pdo.begintransaction.php#90239

of course  this is an PHP example but you can easily convert it to FreePascal

Lacak2

  • Guest
Re: SQLite3 "database is locked"
« Reply #3 on: May 26, 2010, 12:06:05 am »
Thanks for the tips. It seems, that if there is at least one explicit  "read" (select) transaction or at least one implicit transaction with prepared (unfinalized) statement, then SQLite3 holds shared lock on file, so another process can not acquire reserved (exclusive) lock and write updates.

Because I work with high level components sqlDB I can not control SQLite at API level (as required by example in PHP link above).
Any other ideas ?
Other components like TSqlite3Dataset also have this "problem"?

vfclists

  • Hero Member
  • *****
  • Posts: 1013
    • HowTos Considered Harmful?
Re: SQLite3 "database is locked"
« Reply #4 on: June 01, 2010, 04:20:19 am »
The way to handle this then would be to add support for this to the TSQLite3Dataset.

It can't be that hard, can it? ;)

I have come across that problem myself and I am considering FirebirdSQL if it will fix this issue, otherwise SQLite would be my preference.
« Last Edit: June 01, 2010, 04:22:00 am by vfclists »
Lazarus 3.0/FPC 3.2.2

Lacak2

  • Guest
Re: SQLite3 "database is locked"
« Reply #5 on: June 03, 2010, 12:04:26 am »
The way to handle this then would be to add support for this to the TSQLite3Dataset.

It can't be that hard, can it? ;)
It is question for author (LuizAmérico?) :), if he will spend time and if it is doable ... but if possible it will be great.

clauslack

  • Sr. Member
  • ****
  • Posts: 275
Re: SQLite3 "database is locked"
« Reply #6 on: June 11, 2010, 09:07:44 am »
You can try Firebird 2.5

From
http://www.mindthebird.com/download/mtbweb20100406.pdf

Embedded engine uses new architecture
- Host applications may still have multiple connections to the same database
- Different host applications may safely access the same database simultanously
- Official utilities (gbak, gfix, etc) and 3rd party tools
(DBWorkbench, IBExpert, etc) can be used in parallel with your application as well.

Regards

LuizAmérico

  • Sr. Member
  • ****
  • Posts: 457
Re: SQLite3 "database is locked"
« Reply #7 on: June 17, 2010, 02:42:22 pm »
I have an app that 10 instances (in different machines) access a sqlite datafile using TSqlite3DataSet.

The only thing i did is add an OnGetHandle event for each dataset and do small transactions, i.e., after each update/add/delete i call ApplyUpdates

procedure TDataCenter.GenericDatasetGetHandle(Dataset: TDataSet);
begin
  sqlite3_busy_timeout(TSqlite3Dataset(Dataset).SqliteHandle, 1500);
end;

spitofland

  • New Member
  • *
  • Posts: 26
Re: SQLite3 "database is locked"
« Reply #8 on: June 21, 2010, 06:26:46 am »
I have not had a chance to use SQLLite myself, but I have received advice that when using SQLLite you should run the query and then close the connection as soon as you can since SQLLite only allows one connection at a time. This may not prevent all conflicts, but it should help reduce the number of errors.

gajahbengkak

  • New Member
  • *
  • Posts: 13
  • this is me, mine, myself
    • Catatan Si Arief
Re: SQLite3 "database is locked"
« Reply #9 on: October 28, 2016, 08:44:31 pm »
SQLite support multiple read transaction but only one write transaction at the same time so it is wise to close transaction immediately after finish writing to database.

vrull

  • Full Member
  • ***
  • Posts: 118
Re: SQLite3 "database is locked"
« Reply #10 on: November 08, 2016, 03:22:33 am »
I wrote an application that addresses this issue. It uses single connection, to deal with temporary tables, but closes transaction as soon as data are retrieved or saved.
You can download the source from https://sourceforge.net/projects/sqlmm/files/source-code/.
For the grids, it copies dataset into memory, so you can run multiple requests per application / instances.

 

TinyPortal © 2005-2018