【发布时间】: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 模式;打开连接后。