如何将内存流转换为Sqlite db文件 [英] How do I convert a memory stream to Sqlite db file

查看:416
本文介绍了如何将内存流转换为Sqlite db文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在通过在Webapi上构建的休息服务来处理备份.sqlite文件的要求。服务应该接受.sqlite文件作为内存流和存储在数据库中,并通过从存储在数据库中的流转换请求时返回.sqlite文件。我想知道如何从内存sream创建一个sqlite文件。请指导我

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

推荐答案

如果您将内容作为内存流,那么它很简单:

If you have the content as a memory stream, then it's simple:
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:

File.WriteAllBytes(@"D:\Temp\MySqLiteDB.sqlite", arrayOfBytes);



您确定将数据库存储在其他数据库中是个好主意吗?


And are you sure that it's a good idea to store Databases inside other Databases?


这篇关于如何将内存流转换为Sqlite db文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆