简体   繁体   English

如何在C#中更改Sqlite数据库的“ journal_mode”

[英]How to change “journal_mode” of a Sqlite database in C#

Following the instructions of Sqlite's PRAGMA I found that PRAGMA schema.journal_mode; 按照Sqlite的PRAGMA的说明,我发现PRAGMA schema.journal_mode; changes the journal_mode and given the options I chose off to increase performance of insert function. 改变journal_mode并给予我选择的选项off ,以增加插入功能的性能。 I wrote: 我写:

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

which opens a database called MyDatabase.sqlite and the command 这将打开一个名为MyDatabase.sqlite的数据库和命令

PRAGMA Schema.journal_mode=off;

which is written in the end, I believe turns off the journaling of the sqlite database, but I don't have a clue on how to do it and if this is the proper way then what am I doing wrong because I see no change in performance after adding the PRAGMA command. 最后,我相信它会关闭sqlite数据库的日志记录,但是我不知道如何执行该操作,如果这是正确的方法,那我做错了什么,因为我看不到添加PRAGMA命令后的性能。

I downloaded the Sqlite Library from a link referred in Tigran's Blog Post on Sqlite 我从Tigran的Sqlite博客文章中引用的链接下载了Sqlite库

The PRAGMA keyword is not for use in connection strings. PRAGMA关键字不适用于连接字符串。 The proper connection string syntax would be: 正确的连接字符串语法为:

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

One way to discover these is to use the SQLiteConnectionStringBuilder object: 发现这些错误的一种方法是使用SQLiteConnectionStringBuilder对象:

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

string myLtConnStr = lcb.ConnectionString;

Result: 结果:

"journal mode=Off;data source=\\"C:\\SQLite Dbs\\mydata.db\\";version=3" “新闻模式=关闭;数据源= \\” C:\\ SQLite Dbs \\ mydata.db \\“;版本= 3”

Some DB providers have many many options -- particularly with regard to DateTime handling and options -- which can be toggled this way. 一些数据库提供程序有很多选项,尤其是有关DateTime处理和选项的选项,可以通过这种方式进行切换。 Once you know the syntax, you can elide the ConnectionStringBuilder object. 一旦知道语法,就可以取消ConnectionStringBuilder对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM