Search code examples
c#sqliteblob

c# write big files to blob sqlite


I have c# application which writes files to an sqlite database. It uses entity framework for modelling data. It converts the file to a blob (entity byte[] variable) with this line:

row.file = System.IO.File.ReadAllBytes(file_to_load.FileName); //row.file is type byte[]
                                                               //row is entity class table

This works correctly when the file size is less than 300MB. When the file size is more than 300MB, the app throws an exception:

Exception of type 'System.OutOfMemoryException' was thrown.

How I can write to blob direct, without in-memory variables?


Solution

  • You'll have to use so-called Incremental BLOB I/O. See this post on a System.Data.SQLite forum.