2

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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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;
}

Comments

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.