我正在尝试将 BLOB 数据写入 word 文件。这是我的代码
将 reportID 调暗为整数 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()
我一次写 8k,因为我之前在数据很大时遇到内存不足的问题,比如 1GB。而不是上面的代码,如果我使用
Response.BinaryWrite(table2.file_data)
一切正常。
所以请告诉我使用 sqldatareader 的问题是什么?
目前我正在考虑的文件大小是 31794 字节
仅供参考:我正在使用 CommandBehavior.SequentialAccess