Database file is inexplicably locked during SQLite commit

后端 未结 9 738
深忆病人
深忆病人 2020-12-31 12:17

I\'m performing a large number of INSERTS to a SQLite database. I\'m using just one thread. I batch the writes to improve performance and have a bit of security in case of

相关标签:
9条回答
  • 2020-12-31 13:17

    I would always use a Connection, Transaction and Command in a using clause. In your first code listing you did, but your third (creating the tables) you didn't. I suggest you do that too, because (who knows?) maybe the commands that create the table somehow continue to lock the file. Long shot... but worth a shot?

    0 讨论(0)
  • 2020-12-31 13:20

    These guys were having similiar problems (mostly, it appears, with the journaling file being locked, maybe TortoiseSVN interactions ... check the referenced articles).

    They came up with a set of recommendations (correct directories, changing journaling types from delete to persist, etc). http://sqlite.phxsoftware.com/forums/p/689/5445.aspx#5445


    The journal mode options are discussed here: http://www.sqlite.org/pragma.html . You could try TRUNCATE.

    Is there a stack trace during the exception into SQL Lite?

    You indicate you "batch my commits at a reasonable interval". What is the interval?

    0 讨论(0)
  • 2020-12-31 13:22

    I started facing this same problem today: I'm studying asp.net mvc, building my first application completely from scratch. Sometimes, when I'd write to the database, I'd get the same exception, saying the database file was locked.

    I found it really strange, since I was completely sure that there was just one connection open at that time (based on process explorer's listing of active file handles).

    I've also built the whole data access layer from scratch, using System.Data.SQLite .Net provider, and, when I planned it, I took special care with connections and transactions, in order to ensure no connection or transaction was left hanging around.

    The tricky part was that setting a breakpoint on ExecuteNonQuery() command and running the application in debug mode would make the error disappear! Googling, I found something interesting on this site: http://www.softperfect.com/board/read.php?8,5775. There, someone replied the thread suggesting the author to put the database path on the anti-virus ignore list.

    I added the database file to the ignore list of my anti-virus (Microsoft Security Essentials) and it solved my problem. No more database locked errors!

    0 讨论(0)
提交回复
热议问题