c# - 如何在 C# 中更改 Sqlite 数据库的 "journal_mode"

标签 c# sqlite insert sqlite-journal-mode

按照 Sqlite 的 PRAGMA 的说明进行操作我发现 PRAGMA schema.journal_mode; 更改了 journal_mode 并给出了我选择 off 的选项以提高插入功能的性能。我写道:

SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;PRAGMA Schema.journal_mode=off;");

打开名为 MyDatabase.sqlite 的数据库和命令

PRAGMA Schema.journal_mode=off;

写在最后,我相信会关闭 sqlite 数据库的日志记录,但我不知道该怎么做,如果这是正确的方法,那么我做错了什么,因为我明白了添加 PRAGMA 命令后性能没有变化。

我从 Tigran's Blog Post on Sqlite 中提到的链接下载了 Sqlite 库

最佳答案

PRAGMA 关键字不用于连接字符串。正确的连接字符串语法是:

SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;journal mode=Off;");

发现这些的一种方法是使用 SQLiteConnectionStringBuilder 对象:

SQLiteConnectionStringBuilder lcb = new SQLiteConnectionStringBuilder();
lcb.JournalMode = SQLiteJournalModeEnum.Off;
lcb.DataSource = sqlFile;
lcb.Version = 3;

string myLtConnStr = lcb.ConnectionString;

结果:

"journal mode=Off;data source=\"C:\SQLite Dbs\mydata.db\";version=3"

一些数据库提供商有很多选项——特别是关于日期时间处理和选项——可以通过这种方式切换。了解语法后,您可以省略 ConnectionStringBuilder 对象。

关于c# - 如何在 C# 中更改 Sqlite 数据库的 "journal_mode",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46473577/

相关文章:

c# - 带有数据源的 ASP.NET DropDownList 未选择任何项目

c# - 为什么 Resharper 会删除我的评论?

Python SQLite : Is Commit() needed for SELECT Queries?

php - MYSQL 使用 PDO 在不存在的地方插入

c# - 确定高处理器使用率的来源

c# - 如何在 C# 中实现 string(xml) 到 memorystream 文件?

java - 在 Android 的 SQLite 中创建表有问题

android - 将图像存储到android中的SQLite中

php INSERT 到变量名 MySQL 的列

Oracle 'INSERT ALL' 忽略重复项