Reading SQL Varbinary Blob from Database

后端 未结 3 1215
情书的邮戳
情书的邮戳 2021-01-01 18:12

I am working on saving files to sql blob to a varbinary(max) column, and have got the save side of things working now (I believe).

What I can\'t figure out is how to

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-01 18:46

    You will need to use a SqlCommand to retrieve data when data is stored in a varbinary(MAX) column unless you use a FileTable, which allows access to the contents via UNC path similarly to regular files stored on a file system, but managed by SQL Server.

    If the size of the blob may be large, the "chunk" technique you are currently using will reduce memory requirements, but at the expense of more verbose code. For reasonably size blob sizes, you could read the entire column contents at once without a chunking method. Whether this is feasible depends on both the size of the blob and client available memory.

    var buffer = (byte[])cmd.ExecuteScalar();
    fs.Write(buffer, 0, buffer.Length);
    

提交回复
热议问题