IBM.Data.Informix.IfxDataReader.GetBytes problem
Posted in 2005
Hi, Has anyone used GetBytes to successfully read a blob using the IfxDataReader ? The following code (which I got from a MS how-to I believe) works fine to retrieve a blob when I use the ODBC interface (using ODBCDataReader). However the same technique fails under the IFXDataReader with the following message Exception Source: IBM.Data.Informix Exception Type: System.NullReferenceException Exception Message: Object reference not set to an instance of an object. Exception Target Site: GetBytes ---- Stack Trace ---- IBM.Data.Informix.IfxDataReader.GetBytes(i As Int32, dataIndex As Int64, buffer As Byte[], bufferIndex As Int32, length As Int32) DocuViewForms.exe: N 00561 PDFGeneratorClassLibrary.dbPDF.FetchPDFtoFile(booTestMode As Boolean, strRecno As String, strTempPath As String) dbPDF.vb: line 0142, col 13, IL 0222 Here's the code (I've left out the code that sets up bw, a binary writer that writes the blob to a file fs). I've highlighted the code that errors. The code reads 1000 bytes at a time and writes it to a file. As I say. it works fine with ODBC. According to the docs GetBytes is supported by the IFXDataReader. I'm using SDK 2.90. I'd be very grateful for any ideas. '----------------------------------------------------------- ' set up the query string depending on user-supplied data Dim strCommand As String = "SELECT pdf FROM pdfdocument WHERE recno = " & strRecno Dim cmCommand As New IfxCommand(strCommand, dcConnection) Open the connection and read data into the DataReader. NB Sequential Access parm Dim drReaderPDF As IfxDataReader = cmCommand.ExecuteReader(CommandBehavior.SequentialAccess) If drReaderPDF.Read() Then Dim bufferSize As Integer = 1000 ' The size of the BLOB buffer. Dim outbyte(bufferSize - 1) As Byte ' The BLOB byte() buffer to be filled by GetBytes. Dim retval As Long ' The bytes returned from GetBytes. Dim startIndex As Long = 0 ' The starting position in the BLOB output. ' Reset the starting byte for a new BLOB. startIndex = 0 ' Read bytes into outbyte() and retain the number of bytes returned. ' **** THE FOLLOWING LINE ERRORS ***** retval = drReaderPDF.GetBytes(0, startIndex, outbyte, 0, bufferSize) ' Continue reading and writing while there are bytes beyond the size of the buffer. Do While retval = bufferSize bw.Write(outbyte) bw.Flush() ' Reposition the start index to the end of the last buffer and fill the buffer. startIndex += bufferSize retval = drReaderPDF.GetBytes(0, startIndex, outbyte, 0, bufferSize) Loop If retval > 0 Then ' Write the remaining buffer. bw.Write(outbyte, 0, CInt(retval - 1)) bw.Flush() End If ' Close the output file. bw.Close() fs.Close() End If '------------------------------------------------------------------------- Richard Moon