2

I need to read blob data into a memory stream from an Image type column from an SQL Server database. How can I do this using Dapper?

I was reading the Dapper manual but was unable to find information about this.

UPDATE: I need to read the data from the database (from a query). All the links suggested so far has information about how to store the blob in the database.

5
  • 1
    Did you go through the following link : dapper-tutorial.net/knowledge-base/9634587/… Commented Feb 4, 2019 at 23:50
  • Yes I saw both but neither seems to be relevant. I need to read from the server using a query. The links explain how to do it when need to update and insert above 8k data. Commented Feb 5, 2019 at 8:08
  • image is the deprecated name for varbinary(max). Don't use image Commented Feb 5, 2019 at 8:34
  • @AmitJoshi that question has no relevant answer. It's far too old anyway - Dapper went through a lot of changes in the last 7 years Commented Feb 5, 2019 at 8:37
  • @RasanjanaN that's just a reposting of a very old SO question with no relevant answer. That site is NOT an official Dapper site Commented Feb 5, 2019 at 8:39

1 Answer 1

2

Figured it out. The result dynamic type is a byte[].

var row = con.QueryFirst("SELECT BLOBFIELD FROM TABLE WHERE ID = 1");

byte[] bytes = drawings.BLOBFIELD;
using (var stream = new System.IO.FileStream(@"C:\Temp\Test.dat", System.IO.FileMode.CreateNew))
  stream.Write(bytes, 0, bytes.Length);
Sign up to request clarification or add additional context in comments.

2 Comments

In other words, create an object with a byte[] field. The rest of the code isn't relevant. This won't work with large binaries though
@PanagiotisKanavos how it can be made to work with large binaries?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.