如何备份 SQLite 内存数据库?我在我的 Windows 应用程序中创建数据库。我想在关闭应用程序时进行数据库备份。
问问题
20499 次
3 回答
11
您需要SQLite 在线备份 API。
据我所知, System.Data.SQLite 还不支持它,所以你需要编写一些代码。System.Data.SQLite 论坛包含一个示例:http ://sqlite.phxsoftware.com/forums/t/2403.aspx 。如前所述,当您修补 System.Data.SQLite 并直接调用 SQLite 时,您需要自担风险。
于 2011-02-03T19:22:05.337 回答
0
用“基于文件的数据库”替换“内存数据库”怎么样?
如果您关闭应用程序,该文件将仍然存在。
在程序启动时,您必须确保删除数据库文件。
于 2011-02-04T17:46:35.623 回答
-1
你可以试试这个代码
using (var location = new SQLiteConnection(@"Data Source=activeDb.db; Version=3;"))
using (var destination = new SQLiteConnection(@"Data Source=backupDb.db; Version=3;"))
{
location.Open();
destination.Open();
location.BackupDatabase(destination, "main", "main", -1, null, 0);
}
于 2017-08-07T02:06:30.387 回答