SQLite in-memory database backup in .NET

半腔热情 提交于 2019-12-23 07:01:14

问题


How to get the SQLite in-memory data base backed up? I create the database in my Windows application. I want to take a database backup when I will close the application.


回答1:


You want the SQLite Online Backup API.

As far as I know, System.Data.SQLite does not support it yet, so you'll need to write some code. The System.Data.SQLite Forum contains an example: http://sqlite.phxsoftware.com/forums/t/2403.aspx. As noted, when you patch System.Data.SQLite and call SQLite directly you do so at your own risk.




回答2:


what about replacing the "in-memory database" with a "file based database"?

If you close the app the file will then still be there.

At program start you have to make shure that the database file is deleted.




回答3:


you may try this code

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);
}


来源:https://stackoverflow.com/questions/4890122/sqlite-in-memory-database-backup-in-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!