我在我的vb.net程序中使用System.data.sqlite.dll。不管怎么说,我都找不出激活WAL模式的代码。
我是在创建数据库后立即激活该命令,还是在每次创建新的SQLiteConnection时激活该命令。
如果是这样的话,现在需要使用什么代码,我使用的代码如下:
cnn As New SQLiteConnection(String.Format("Data Source={0}\{1};PRAGMA jounal_mode=WAL;", Application.StartupPath, DBName))这就是PRAGMA命令的用法吗?
发布于 2012-05-10 18:13:12
您可以随时使用SQLiteConnectionStringBuilder类为您完成此工作:
SQLiteConnectionStringBuilder connBuilder = new SQLiteConnectionStringBuilder();
connBuilder.DataSource = filePath;
connBuilder.Version = 3;
//Set page size to NTFS cluster size = 4096 bytes
connBuilder.PageSize = 4096;
connBuilder.CacheSize = 10000;
connBuilder.JournalMode = SQLiteJournalModeEnum.Wal;
connBuilder.Pooling = true;
connBuilder.LegacyFormat = false;
connBuilder.DefaultTimeout = 500;
connBuilder.Password = "yourpass";
using(SQLiteConnection conn = new SQLiteConnection(connBuilder.ToString()))
{
//Database stuff
}发布于 2012-05-26 17:58:49
这是我的项目(App.config)中的连接字符串示例:
<connectionStrings>
<add name="SQLiteDb" providerName="System.Data.SQLite" connectionString="Data Source=data.sqlite;Version=3;Pooling=True;Synchronous=Off;journal mode=Memory"/>
</connectionStrings>您可以指定journal mode=WAL而不是journal mode=Memory。
如果您没有在连接字符串中指定日志模式,您可以通过对数据库执行PRAGMA jounal_mode=WAL查询来手动切换。
发布于 2011-12-31 11:32:38
您需要将杂注作为一个非查询命令来执行。
Using cmd As SQLiteCommand = cnn.CreateCommand()
cmd.CommandText = "PRAGMA journal_mode=WAL"
cmd.ExecuteNonQuery()
End Using只要你保持你的连接是开放的,setting this once就足够了。
https://stackoverflow.com/questions/8685897
复制相似问题