【问题标题】:How to change "journal_mode" of a Sqlite database in C#如何在 C# 中更改 Sqlite 数据库的“journal_mode”
【发布时间】:2018-03-10 11:00:51
【问题描述】:

按照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 库

【问题讨论】:

    标签: c# sqlite insert sqlite-journal-mode


    【解决方案1】:

    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;
    

    结果:

    "日志模式=关闭;数据源=\"C:\SQLite Dbs\mydata.db\";版本=3"

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

    【讨论】:

    • 请注意,在阅读了您之前的问题后,我怀疑大部分问题出在您的代码上,而不是 SQLite 插入所需的时间。
    • 是的,我发现我没有使用正在交易的方法
    猜你喜欢
    • 1970-01-01
    • 2011-07-07
    • 1970-01-01
    • 2013-11-26
    • 1970-01-01
    • 2014-04-28
    • 2011-02-14
    • 1970-01-01
    • 2012-05-28
    相关资源
    最近更新 更多