【问题标题】:SQLite refuces to be set to WAL with Microsoft.Data.Sqlite .Net 7 in C#SQLite 拒绝在 C# 中使用 Microsoft.Data.Sqlite .Net 7 设置为 WALK
【发布时间】:2023-01-26 04:23:28
【问题描述】:

我无法以编程方式为 SQLite 设置 WAL 模式。 创建数据库文件时调用我的代码

var conn = new SqliteConnection(_connectionString);
            await using(conn.ConfigureAwait(false))
            {
                await conn.OpenAsync().ConfigureAwait(false);
                var trans = await conn.BeginTransactionAsync().ConfigureAwait(false);
                await using(trans.ConfigureAwait(false))
                {
                    var command = conn.CreateCommand();
                    await using(command.ConfigureAwait(false))
                    {
                        command.CommandType = CommandType.Text;
                        command.CommandText = $"PRAGMA journal_mode = WAL;";
                        await command.ExecuteNonQueryAsync().ConfigureAwait(false);
                    }
                    var command2 = conn.CreateCommand();
                    await using(command2.ConfigureAwait(false))
                    {
                        command2.CommandType = CommandType.Text;
                        command2.CommandText = $"PRAGMA wal_autocheckpoint=1000;";
                        await command2.ExecuteNonQueryAsync().ConfigureAwait(false);
                    }
                    trans.Commit();
                }
                //Set Settings
            }

当我再次打开数据库时,journal_mode 为 DELETE。但是 wal_autocheckpoint 正确设置为 1000。 使用 DB Browser for SQLite 并运行相同的命令。 我尝试了我能想到的任何东西。我什至将两个 PRAGMA 拆分为单独的命令。原来他们合二为一

$"PRAGMA journal_mode = WAL;{Environment.NewLine}PRAGMA wal_autocheckpoint=1000;"

有任何想法吗?

我期望在运行代码并打开数据库处于 WAL 模式的 SQLite 数据库之后。

【问题讨论】:

  • 在开始交易之前切换到 WAL 模式;打开连接后。

标签: c# .net sqlite wal


【解决方案1】:

@Mark Benningfield 击中现场。 在 PRAGMA journal_mode = WAL 之后移动 BeginTransactionAsync 之后;命令日志模式设置正确。

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-09
    • 2013-03-25
    • 2011-03-31
    • 1970-01-01
    • 1970-01-01
    • 2013-10-27
    • 1970-01-01
    • 2019-03-09
    相关资源
    最近更新 更多