SQLite数据库文件使用后无法重命名

发布于 2024-08-17 08:52:09 字数 592 浏览 3 评论 0原文

我正在尝试在使用完 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷血 2024-08-24 08:52:09

我假设您正在使用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.

清眉祭 2024-08-24 08:52:09

DBCommandIDisposable。也许您需要对其调用 Dispose 或在 using 语句中创建它。

DBCommand is IDisposable. Maybe you need to call Dispose on it or create it in a using statement.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文