Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to take Sqlite database backup using C# or Sqlite query

Memory Stream as DB

I have used code on this link which gave me errormessage that

BackupDatabase() does not exists in System.Data.Sqlite.SqliteConnection

Is there any Sqlite query to backup or export Sqlite database. And then restore it again

I want to export database on one system and then import it in another system for same windows application installed on both systems. I want to implement this activities on button click.

like image 901
Ajay Avatar asked Jun 07 '26 18:06

Ajay


1 Answers

backup database link in Sqlite link try this function

public void backup(string strDestination)
{
      using (var location = new SQLiteConnection(@"Data Source=C:\activeDb.db; Version=3;"))
      using (var destination = new SQLiteConnection(string.Format(@"Data Source={0}:\backupDb.db; Version=3;", strDestination)))
      {
          location.Open();
          destination.Open();
          location.BackupDatabase(destination, "main", "main", -1, null, 0);
      }
}
like image 125
Ramgy Borja Avatar answered Jun 10 '26 06:06

Ramgy Borja



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!