SQLite数据库文件使用后无法重命名
我正在尝试在使用完 SQLite 数据库文件后重命名它,但是即使在所有连接都关闭后,该文件似乎仍然由 SQLite 打开。
以下是我正在执行的操作的示例:
using (DbConnection conn = new SQLiteConnection("Data Source=test.db"))
{
conn.Open();
DbCommand command = conn.CreateCommand();
command.CommandText = "select id from test";
command.ExecuteScalar();
}
File.Move("test.db", "test.db.test");
Move
调用抛出 IOException。这是我与该数据库文件的唯一连接。应用程序结束后,我可以毫无问题地手动移动文件。我尝试过各种方法,例如在连接字符串中显式设置 Pooling=false
、在连接释放之前手动调用 Close
、显式启动并提交事务,但没有这似乎有帮助。有没有办法强制 SQLite 关闭/释放数据库文件而不退出应用程序?
I'm trying to rename my SQLite database file after I'm done using it, however the file still appears to be opened by SQLite even after all my connections are closed.
Here is an example of what I'm doing:
using (DbConnection conn = new SQLiteConnection("Data Source=test.db"))
{
conn.Open();
DbCommand command = conn.CreateCommand();
command.CommandText = "select id from test";
command.ExecuteScalar();
}
File.Move("test.db", "test.db.test");
The Move
call throws an IOException. This is the only connection that I have to this database file. Once the application ends I can move the file manually without a problem. I've tried various things such as explicitly setting Pooling=false
in the connection string, manually calling Close
before the connection is disposed, explicitly starting and committing a transaction, but none of this seems to help. Is there a way to force SQLite to close/release the database file without exiting the application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您正在使用SQLite.Net?我刚刚尝试过你的代码,并且在 Vista 上的 VS 2005 中使用 SQLite.Net 1.0.65 时没有问题。
I presume you are using SQLite.Net? I have just tried your code and works without problem with SQLite.Net 1.0.65, in VS 2005 on Vista.
DBCommand
是IDisposable
。也许您需要对其调用Dispose
或在using
语句中创建它。DBCommand
isIDisposable
. Maybe you need to callDispose
on it or create it in ausing
statement.