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.

2
  • possible duplicate of C# SQLite Memory Stream as DB Commented Sep 17, 2013 at 19:34
  • What an absurd illogical question for a software engineer. Backup => persist physically somewhere (not inmemory anymore!) , not to another RAM in another running machine! Commented Aug 25, 2023 at 0:08

3 Answers 3

11

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Documentation: "online backup API allows the contents of one database to be copied into another database file" The question is absurd.. any "backup" will be persisted in non memory (non-ram)!
1

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

2 Comments

Your Answer is out of context because Question is about in-memory not file base DB
This answer is not out-of-context. The question is absurd -- as that "Software engineer' did not understand the meaning of the word physical-persistence in the context of backup.
0

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.

1 Comment

No... actually we only want to use in memory database. That is our prime requirement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.