I my database we have a varbinary field which store file content in byte.

As the file is big and reading all content in one shot leads to time-out so I want to read that data in chunk like we have write function in sql to write data using chunk.

Please suggest any idea?

Thanks

share|improve this question
feedback

2 Answers

To do that via a simple SELECT ..., you can drop to ADO.NET, i.e. ExecuteReader, specifying the CommandBehaviour.SequentialAccess flag. Now you can call repeatedly the GetBytes method to read sequential chunks into a buffer. For example:

byte[] buffer = new byte[8040];
int bytes;
long offset = 0;
while((bytes = (int)reader.GetBytes(col, offset, buffer, 0, buffer.Length)) >0) {
    // TODO: do something with `bytes` bytes from `buffer`
    offset += bytes;
}
share|improve this answer
Thanks for your comment...... – Parag Vyas Jun 18 at 14:12
feedback

Have you looked at the FILESTREAM data type?

More info about how to do it http://weblogs.asp.net/aghausman/archive/2009/03/16/saving-and-retrieving-file-using-filestream-sql-server-2008.aspx

share|improve this answer
yes it is sql-server 2008..... – Parag Vyas Jun 14 at 14:58
Ah, good. Should have read the tags. :) – podiluska Jun 14 at 15:00
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.