Sqlite Online Backup Using System.Data.Sqlite

给你一囗甜甜゛ 提交于 2019-11-30 12:40:38

问题


How can a sqlite database be backed up in native C# code while the database is still online? All of the online backup api examples are in C code.


回答1:


The online backup API was added to System.Data.Sqlite in version 1.0.80.0 - April 1, 2012. You can create a database backup while there are other external connections like so

using(var source = new SQLiteConnection("Data Source=ActiveDb.db; Version=3;"))
using(var destination = new SQLiteConnection("Data Source=BackupDb.db; Version=3;"))
{
    source.Open();
    destination.Open();
    source.BackupDatabase(destination, "main", "main", -1, null, 0);
}

Also, BackupDb.db will be created if it doesn't already exist.



来源:https://stackoverflow.com/questions/30129531/sqlite-online-backup-using-system-data-sqlite

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