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.
-
possible duplicate of C# SQLite Memory Stream as DBlxa– lxa2013-09-17 19:34:08 +00:00Commented 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!Espresso– Espresso2023-08-25 00:08:33 +00:00Commented Aug 25, 2023 at 0:08
Add a comment
|
3 Answers
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.
1 Comment
Espresso
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)!
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
Umer Zaman
Your Answer is out of context because Question is about in-memory not file base DB
Espresso
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.
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
Omkar
No... actually we only want to use in memory database. That is our prime requirement.