I have a large file on disk whose contents I need to store in a SqlServer database as a VARBINARY(MAX)
field. By "contents", I mean using something like File.ReadAllBytes()
. (I understand the pitfalls of this, but it's the current mode of operations, so I have to deal with it for now.)
I found this answer, which provides a way to stream a large Byte[]
by using UPDATE.WRITE
:
However, simply reading the contents of a large file into a Byte[]
in memory leads to this problem:
OutOfMemoryException when I read 500MB FileStream
I might be overlooking something obvious, but I just can't work out how should I go about getting from a large file on disk, to the resulting storage into the database.