Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am working on a requirement to backup .sqlite files through rest services build on Webapi.The service should accept .sqlite file as memory stream and store in database and also return the .sqlite file when requested by converting from stream stored in the database.I want to know how can I create a sqlite file from memory sream.Please guide me
Posted
Updated 15-Nov-17 10:42am
Comments
Mehdi Gholam 23-Sep-15 1:43am    
What have you done so far?

1 solution

If you have the content as a memory stream, then it's simple:
C#
using (FileStream fs = new FileStream(@"D:\Temp\MySqLiteDB.sqlite", FileMode.Create, System.IO.FileAccess.Write)) 
   {
   memoryStream.WriteTo(fs);
   }

But...the chances are you actually get it from your DB as an array of bytes - and that's even easier:
C#
File.WriteAllBytes(@"D:\Temp\MySqLiteDB.sqlite", arrayOfBytes);

And are you sure that it's a good idea to store Databases inside other Databases?
 
Share this answer
 
Comments
bschuber 12-Mar-18 14:39pm    
Can it be done in memory, instead of creating a physical file?
OriginalGriff 12-Mar-18 15:00pm    
You want to do backups to memory rather than a non-volatile medium?

A hardware engineer I worked with would describe that as "a somewhat esoteric solution, don't you think?"
He used that phrase when the client asked for something that would defeat the whole idea it was supposed to solve...
bschuber 12-Mar-18 23:29pm    
Actually no.
1. Caller turns the database to a Filestream^
2. Caller calls ToArray on FileStream^, yielding byte array.
3. Caller passes Byte Array to company service on the cloud.
4. Company service passes bytearray to my conversion object.
5. Somehow, my conversion object needs to turn that Byte Array back into a database, without touching the hard drive.
6. My conversion object creates an output file, maps fields from tables in the database to fields in the output file, and turns the output file into a different byte array.
7. I return the converted byteArray to the service, which returns the converted byte array to the calling method.
8. Yes, it is possible they might store the database in a table as a blob, but I do not know that -- all I know is that I receive a byte array that, if I make up a fake name and write the file on disk, is a sqlite database. But they do not want me to do the disk part, because it is on the cloud.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900