sqlite3.OperationalError: database is locked

て烟熏妆下的殇ゞ 提交于 2020-05-11 05:34:06

问题


I'm trying to insert all values of a list to my sqlite3 database. When I simulate this query by using the python interactive interpreter, I am able to insert the single value to DB properly. But my code fails while using an iteration:

...
connection=lite.connect(db_name)
cursor=connection.cursor()
for name in match:
         cursor.execute("""INSERT INTO video_dizi(name) VALUES (?)""",(name,))
connection.commit()
...

error:cursor.execute("""INSERT INTO video_dizi(name) VALUES (?)""",(name,))
sqlite3.OperationalError: database is locked

Any way to overcome this problem?


回答1:


Do you have another connection elsewhere in your code that you use to begin a transaction that is still active (not committed) when you try to commit the operation that fails?




回答2:


Because your database is use by another process or connection. If you need real concurrency, use a real RDBMS.




回答3:


As this error can happen because you have opened your site.db or database file in DBbrowser type application to view in interactive database interface. Just close that it will work fine.



来源:https://stackoverflow.com/questions/5529820/sqlite3-operationalerror-database-is-locked

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!