小智 35
您可以使用能够将db文件复制到内存,将内存复制到文件的SQLite Online Backup API.System.Data.SQLite中存在对SQLite Online Backup API的本机支持,版本为1.0.80.0(使用SQLite 3.7.11).
这是一个简单的例子,如何在C#中使用API:
SQLiteConnection source = new SQLiteConnection("Data Source=c:\\test.db");
source.Open();
using (SQLiteConnection destination = new SQLiteConnection(
"Data Source=:memory:"))
{
destination.Open();
// copy db file to memory
source.BackupDatabase(destination, "main", "main",-1, null, 0);
source.Close();
// insert, select ,...
using (SQLiteCommand command = new SQLiteCommand())
{
command.CommandText =
"INSERT INTO t1 (x) VALUES('some new value');";
command.Connection = destination;
command.ExecuteNonQuery();
}
source = new SQLiteConnection("Data Source=c:\\test.db");
source.Open();
// save memory db to file
destination.BackupDatabase(source, "main", "main",-1, null, 0);
source.Close();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16634 次 |
| 最近记录: |