sqlite error database is locked

后端 未结 8 1224
天命终不由人
天命终不由人 2020-12-06 08:00

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

8条回答
  •  渐次进展
    2020-12-06 08:30

    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.

提交回复
热议问题