Lazarus
Programming => Databases => Topic started 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
-
How did you lock it?
Are you sure there is no process running that has the database open for Write operations?
-
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
-
https://stackoverflow.com/questions/151026/how-do-i-unlock-a-sqlite-database
deal with the same problem
-
Hi
Ok, tried that, no luck :(
I may just have to export the bastard to another db-file %)
Regards Benny
-
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.
-
Hi
Ok, so here's one solution to the problem:
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
-
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 :)
-
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