Recent

Author Topic: [SOLVED] Unlocking a Sqlite3 db-file  (Read 768 times)

cdbc

  • Sr. Member
  • ****
  • Posts: 353
    • http://www.cdbc.dk
[SOLVED] Unlocking a Sqlite3 db-file
« on: January 21, 2021, 07:33:03 pm »
Hi
Well, here i go again...
I succeeded in locking my sqlite3 database file  :(
Any thoughts on how to unlock it again?!?
At the moment, it is readonly.
Any help will be appreciated.
TIA
Regards Benny
« Last Edit: January 22, 2021, 07:30:01 pm by cdbc »
If it ain't broke, don't fix it ;)

JanRoza

  • Hero Member
  • *****
  • Posts: 618
    • http://www.silentwings.nl
Re: Unlocking a Sqlite3 db-file
« Reply #1 on: January 21, 2021, 07:38:43 pm »
How did you lock it?
Are you sure there is no process running that has the database open for Write operations?
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
Laz: Lazarus 2.0.12 FPC 3.2.0
       CodeTyphon 7.4 FPC 3.3.1

cdbc

  • Sr. Member
  • ****
  • Posts: 353
    • http://www.cdbc.dk
Re: Unlocking a Sqlite3 db-file
« Reply #2 on: January 22, 2021, 11:54:32 am »
Hi
I don't know how it got locked ?!?
There shouldn't be other processes accessing the db
It just suddenly happened...
My connection gets created at startup and closed on destroy, I use only 1 connection shared in the entire application.
Regards Benny
If it ain't broke, don't fix it ;)

af0815

  • Hero Member
  • *****
  • Posts: 653
Re: Unlocking a Sqlite3 db-file
« Reply #3 on: January 22, 2021, 03:31:33 pm »
regards
Andreas

cdbc

  • Sr. Member
  • ****
  • Posts: 353
    • http://www.cdbc.dk
Re: Unlocking a Sqlite3 db-file
« Reply #4 on: January 22, 2021, 03:54:00 pm »
Hi
Ok, tried that, no luck  :(
I may just have to export the bastard to another db-file  %)
Regards Benny
If it ain't broke, don't fix it ;)

JanRoza

  • Hero Member
  • *****
  • Posts: 618
    • http://www.silentwings.nl
Re: Unlocking a Sqlite3 db-file
« Reply #5 on: January 22, 2021, 04:50:24 pm »
You could try to look at your database with a db manager program like the free SQLiteExpert Personal (http://www.sqliteexpert.com/), it lets you manage the locking mode on a database level.
Maybe that will help.
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
Laz: Lazarus 2.0.12 FPC 3.2.0
       CodeTyphon 7.4 FPC 3.3.1

cdbc

  • Sr. Member
  • ****
  • Posts: 353
    • http://www.cdbc.dk
Re: Unlocking a Sqlite3 db-file
« Reply #6 on: January 22, 2021, 07:14:13 pm »
Hi
Ok, so here's one solution to the problem:
Code: [Select]
1) Open your terminal and cd to your db-directory
2) Type sqlite3 your_database_name.your_extension
    you are now in the sqlite3 management prompt:
    SQLite version 3.34.1 2021-01-20 14:10:07
    Enter ".help" for usage hints.
3) Type .clone new_database_name.your_extension
4) Type .quit
5) You are now back in terminal
6) Check that your new db works as expected in your
    app
7) Delete the old db-file and rename the new one
8) Type exit and "Bob's your uncle"
sqlite3 comes with sqlite3 installation
Hope that others may find it useful  ;)
Regards Benny
« Last Edit: January 22, 2021, 07:18:06 pm by cdbc »
If it ain't broke, don't fix it ;)

lucamar

  • Hero Member
  • *****
  • Posts: 3741
Re: [SOLVED] Unlocking a Sqlite3 db-file
« Reply #7 on: January 22, 2021, 09:08:55 pm »
A better solution would have been trying to find out what you did to lock it and, if possible, undo it. Having to clone/rename the database without knowing why it happened is just a crutch, IMHO :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

cdbc

  • Sr. Member
  • ****
  • Posts: 353
    • http://www.cdbc.dk
Re: [SOLVED] Unlocking a Sqlite3 db-file
« Reply #8 on: January 24, 2021, 12:29:37 pm »
Hi
@lucamar: Oh I did that, and I had accidently introduced an error, that killed the connection in the middle of a transaction  %) I know, not too clever...
Refactoring didn't go so well in this case  :D
It's fixed and all is well.
Regards Benny
If it ain't broke, don't fix it ;)

 

TinyPortal © 2005-2018