I'm trying to write BLOB data on to a word file. Here is my code
Dim reportID As Integer reportID = table1.report_output_data_id
Dim aSqlStr As String = "SELECT file_data FROM table2 WHERE report_output_data_id = " + Convert.ToString(reportID )
Dim reader As SqlDataReader = CType(WebSession.DataObjectFactory.GetDataProvider("EGDatabase"), cDataProviderSQL).PopulateDataReader(aSqlStr)
' The size of the BLOB buffer.
Dim bufferSize As Integer = 8192
' The BLOB byte() buffer to be filled by GetBytes.
Dim outByte(bufferSize - 1) As Byte
' The bytes returned from GetBytes.
Dim retval As Long
' The starting position in the BLOB output.
Dim startIndex As Long = 0
Do While reader.Read()
' Reset the starting byte for a new BLOB.
startIndex = 0
' Read bytes into outByte() and retain the number of bytes returned.
retval = reader.GetBytes(0, startIndex, outByte, 0, bufferSize)
' Continue while there are bytes beyond the size of the buffer.
Do While retval = bufferSize
Response.BinaryWrite(outByte)
' Reposition start index to end of the last buffer and fill buffer.
startIndex += bufferSize
retval = reader.GetBytes(0, startIndex, outByte, 0, bufferSize)
Loop
Response.BinaryWrite(outByte)
Loop
reader.Close()
I'm writing 8k at a time as I had out of memory issues earlier when data is large say 1GB. Instead of the above code, If I use
Response.BinaryWrite(table2.file_data)
Everything works fine.
So please tell me whats the issue in using sqldatareader?
The file size currently I'm considering is 31794 bytes
FYI: I'm using CommandBehavior.SequentialAccess