Zobacz ten znakomity article here lub ten blog post, aby uzyskać długie wyjaśnienie, jak to zrobić.
Zasadniczo, musisz użyć SqlDataReader i określić SequentialAccess
do niego podczas tworzenia - wtedy możesz odczytać (lub zapisać) BLOB z bazy danych w kawałkach o jakikolwiek rozmiar jest najlepszy dla ciebie.
Zasadniczo coś takiego:
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
Istnieje kilka ważnych problemów w tym; nie zwiększasz przesunięcia danych i nie przetwarzasz bufora końcowego, jeśli ostatni blok nie jest kompletnym ładowaniem bufora ... –
Myślę, że przesunięcie danych jest inkrementowane (startIndex + = bufferSize) - Nie? Tak - ostatni niekompletny bufor nie jest tutaj pokazany - jest to fragment dłuższego artykułu, do którego się przyłączyłem, aby zilustrować najważniejsze fragmenty mechanizmu - to ** nie ** kompletny działający fragment kodu –
OK; "moje złe" w offsecie ;-p –