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.
Asked
Active
Viewed 2.2k times
14
-
possible duplicate of [C# SQLite Memory Stream as DB](http://stackoverflow.com/questions/11383775/c-sharp-sqlite-memory-stream-as-db) – lxa Sep 17 '13 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! – Espresso Aug 25 '23 at 00:08
3 Answers
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.

Corbin March
- 25,526
- 6
- 73
- 100
-
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)! – Espresso Aug 25 '23 at 00:12
0
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);
}

Ramgy Borja
- 2,330
- 2
- 19
- 40
-
Your Answer is out of context because Question is about in-memory not file base DB – Umer Zaman Aug 03 '18 at 08:10
-
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. – Espresso Aug 25 '23 at 00:10
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.

k3b
- 14,517
- 7
- 53
- 85
-
3No... actually we only want to use in memory database. That is our prime requirement. – Omkar Feb 07 '11 at 07:55