I am have a sqlite database in the iPhone application I am writing. I get an error with following code that I am running in a background thread. In the background thread, I
If you have tried sqlite3_close(DB)
it's probably because your methods are trying to access the same database at the same time.
Try to place this line of code
sqlite3_busy_timeout(DB, 500);
somewhere between sqlite3_open
and sqlite3_prepare_v2
in the method from where you get the "database is locked"-error message.
The database-connection in that method will then try to write/read in 500 milliseconds before it gives up, which is usually enough time to escape the locking.
For one thing, you're not closing the database connection with sqlite3_close() before you open a new connection
I had the same problem a while ago. I tried copying the database file itself, renamed it to different filename, then checked it - It actually WORKED!
I am using SQLite3.
I hope this will also work for you!
I just spent an hour with the same problem. The problem for me arose when i unwittingly killed a process by closing the shell (when the script was running a while loop and timer), while a db journal temp file was still opened. Windows does not kill the process even though you have killed it in Python, regardless if you have used db.close() or finalize in the script; if you exit all Python apps there will still be one running in the Task manager.
Hence you will need to end all Python processes in Windows Task Manager, restart them, and it should be fine(if that is actually the cause of the problem).
your database is open close it using sqlite3_close(db) if you dont close then the process which accessed your database will be running background which will cause database is locked error.
if you want to remove database is locked error then follow these steps 1.copy your database file to some other location. 2.then replace the database with the copied database 3.this will dereference all processes which were accessing your database file
you must always close the sqlite database after using it ... so add this line sqlite3_close(DB);
just after sqlite3_finalize(statement);
Update -
You are returning YES in one of your while loop -
while (sqlite3_step(statement) == SQLITE_ROW)
{
return YES;
break;
}
so here you are nither finalizing nor closing the database.. you need to close if everytime you open it