Consulte este excelente article here o este blog post para obtener una explicación larga de cómo hacerlo.
Básicamente, debe usar un SqlDataReader y especificar SequentialAccess
al crearlo, entonces puede leer (o escribir) el BLOB de la base de datos en fragmentos del tamaño que sea mejor para usted.
Básicamente algo como:
SqlDataReader myReader = getEmp.ExecuteReader(CommandBehavior.SequentialAccess);
while (myReader.Read())
{
int startIndex = 0;
// Read the bytes into outbyte[] and retain the number of bytes returned.
retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize);
// Continue reading and writing while there are bytes beyond the size of the buffer.
while (retval == bufferSize)
{
// write the buffer to the output, e.g. a file
....
// Reposition the start index to the end of the last buffer and fill the buffer.
startIndex += bufferSize;
retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize);
}
// write the last buffer to the output, e.g. a file
....
}
// Close the reader and the connection.
myReader.Close();
Marc
Hay algunos problemas importantes en eso; no está incrementando el offset de datos, y no está procesando el búfer final si el último bloque no es una carga de búfer completa ... –
Creo que el desplazamiento de datos se está incrementando (startIndex + = bufferSize) - ¿no? Sí - el último buffer incompleto no se muestra aquí - esto es un extracto del artículo más largo al que me he vinculado, para ilustrar los aspectos más importantes del mecanismo: ** no ** es una pieza de código de trabajo completa –
OK; "my bad" en el offset ;-p –