Lazarus

Programming => Databases => Topic started by: cdbc on January 21, 2021, 07:33:03 pm

Title: [SOLVED] Unlocking a Sqlite3 db-file
Post by: cdbc 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
Title: Re: Unlocking a Sqlite3 db-file
Post by: JanRoza 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?
Title: Re: Unlocking a Sqlite3 db-file
Post by: cdbc 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
Title: Re: Unlocking a Sqlite3 db-file
Post by: af0815 on January 22, 2021, 03:31:33 pm
https://stackoverflow.com/questions/151026/how-do-i-unlock-a-sqlite-database

deal with the same problem
Title: Re: Unlocking a Sqlite3 db-file
Post by: cdbc 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
Title: Re: Unlocking a Sqlite3 db-file
Post by: JanRoza 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/ (http://www.sqliteexpert.com/)), it lets you manage the locking mode on a database level.
Maybe that will help.
Title: Re: Unlocking a Sqlite3 db-file
Post by: cdbc 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
Title: Re: [SOLVED] Unlocking a Sqlite3 db-file
Post by: lucamar 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 :)
Title: Re: [SOLVED] Unlocking a Sqlite3 db-file
Post by: cdbc 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
TinyPortal © 2005-2018