内存流作为数据库

我目前正在考虑使用SQLite作为我的C#项目的数据库引擎,但我遇到了以下问题:我找不到任何用于内存存储的API。 我想要实现的目标如下:

在程序启动时,我想将db文件(从HDD)加载到内存中。 在执行程序期间,我想将此内存流用作真正的数据库(读取,写入,插入,选择等)。 关闭后将流保存到文件中。

任何人都可以以正确的方式指出我或建议另一个更适合此目的的数据库引擎。

您可以使用能够将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(); }