最佳答案
在试图删除文件之前,我的数据库关闭出现了问题
myconnection.Close();
File.Delete(filename);
Delete 引发文件仍在使用的异常。几分钟后,我在调试器中重试了 Delete () ,所以这不是计时问题。
I have transaction code but it doesn't run at all before the Close() call. So I'm fairly sure it's not an open transaction. The sql commands between open and close are just selects.
ProcMon 在数据库文件中显示了我的程序和防病毒程序。它没有显示我的程序在 close ()之后释放 db 文件。
Visual Studio 2010,C # ,System. Data.SQLite version 1.0.77.0,Win7
我看到一个两年前的 bug 就像这样但是变更日志显示它已经修复了。
还有什么我可以查的吗?是否有办法获得任何打开的命令或事务的列表?
新的工作代码:
db.Close();
GC.Collect(); // yes, really release the db
bool worked = false;
int tries = 1;
while ((tries < 4) && (!worked))
{
try
{
Thread.Sleep(tries * 100);
File.Delete(filename);
worked = true;
}
catch (IOException e) // delete only throws this on locking
{
tries++;
}
}
if (!worked)
throw new IOException("Unable to close file" + filename);