Sqlite python sqlite3.OperationalError: database is locked
I'm not sure if this will help anyone, but I figured out a solution to my own Locked Database problem.
I use PyCharm and found that several instances of the script I was working on were all running. This was usually due to errors in the code I was testing, but it stayed active (and therefore the connection to the db was still active). Close out of those (stop all the processes) and try again - it has worked every time for me!
If anyone knows a way to make it timeout after a little while, please comment this solution. I tried cur.execute("PRAGMA busy_timeout = 30000")
(found from another thread on a similar question) but it didn't seem to do anything.
"Database is locked" means that some other connection has an active connection.
Use PRAGMA busy_timeout to wait some time for the other transaction to finish:
conn.execute("PRAGMA busy_timeout = 30000") # 30 s
However, if that other application deliberately keeps an open transaction to keep the database locked, there is nothing you can do.
cursor2 = conn.cursor()cursor3 = conn.cursor()cursor4 = conn.cursor()
I think you have to close the connection which you have opened,may be the error is because of that cause you have opened multiple connections.
cursor2 = conn.cursor()"""EDIT YOUR DATABASE USING CODE AND CLOSE THE CONNECTION"""connection.close()cursor3 = conn.cursor()"""EDIT YOUR DATABASE USING CODE AND CLOSE THE CONNECTION"""connection.close()cursor4 = conn.cursor()"""EDIT YOUR DATABASE USING CODE AND CLOSE THE CONNECTION"""connection.close()