What is the most efficient way to read many bytes from SQL Server using SqlDataReader (C#)
Posted
by eccentric
on Stack Overflow
See other posts from Stack Overflow
or by eccentric
Published on 2010-05-20T15:48:05Z
Indexed on
2010/05/20
15:50 UTC
Read the original article
Hit count: 178
Hi everybody! What is the most efficient way to read bytes (8-16 K) from SQL Server using SqlDataReader. It seems I know 2 ways:
byte[] buffer = new byte[4096];
MemoryStream stream = new MemoryStream();
long l, dataOffset = 0;
while ((l = reader.GetBytes(columnIndex, dataOffset, buffer, 0, buffer.Length)) > 0)
{
stream.Write(buffer, 0, buffer.Length);
dataOffset += l;
}
and
reader.GetSqlBinary(columnIndex).Value
The data type is IMAGE
© Stack Overflow or respective owner