OdbcDataReader and Oracle BLOB data

G

Guest

Hello, I am attempting to retrieve BLOB data from an Oracle 9.0.2 Database. I
ma using the GetBytes() method of the ODBCDataReader and am running it some
issues with larger documents.

The Code:

Private Function RetrieveBlob(ByVal lngFormSeq As Integer) As Boolean
'***********************************************************
'DESCRIPTION:
' Retrieves a binary file from the database.
'
'PARAMETERS:
' lngFormSeq - Sequence # of form being retrieved.
'***********************************************************
Dim comGetBlob As New OdbcCommand
Dim bufferSize As Integer = 1024000
Dim outbyte(bufferSize - 1) As Byte 'Byte array for Blob data
Dim strSQL As String
Dim startIndex As Long = 0
Dim retval As Long

Try
strSQL = "SELECT Word_Document_Blob FROM rums.Rums_Form_Doc " & _
"WHERE Form_Seq = " & lngFormSeq

comGetBlob.Connection = RUMSDB
comGetBlob.CommandType = CommandType.Text
comGetBlob.CommandText = strSQL
Dim rdrGetBlob As OdbcDataReader =
comGetBlob.ExecuteReader(CommandBehavior.SequentialAccess)

If Not rdrGetBlob.HasRows Then
Script_Literal.Text = HandleException(ErrFAFileNotFound)
Exit Function
End If

'Open/Download the document
Response.Buffer = True
Response.Clear()
Response.AppendHeader("Content-Disposition", "; filename=" & strDestFileName)
Response.ContentType = "application/msword"
Do While rdrGetBlob.Read()
startIndex = 0
retval = rdrGetBlob.GetBytes(0, startIndex, outbyte, 0, bufferSize)
Do While retval = bufferSize
Response.BinaryWrite(outbyte)
startIndex += bufferSize
retval = rdrGetBlob.GetBytes(0, startIndex, outbyte, 0, bufferSize)
Loop
Response.BinaryWrite(outbyte)
Response.Flush()
Loop
rdrGetBlob.Close()
rdrGetBlob = Nothing
RetrieveBlob = True
Catch ex As System.Exception
RetrieveBlob = False
System.Diagnostics.Debug.Assert(False, ex.ToString & ControlChars.NewLine)
System.Diagnostics.Debug.Write(ex.ToString & ControlChars.NewLine)
System.Diagnostics.Debug.Write(Err.Number & " " & Err.Description &
ControlChars.NewLine)
If Err.Number = ErrFAFileAlreadyExists Then
Script_Literal.Text = HandleException(ErrFAFileAlreadyExists)
Else
Script_Literal.Text = HandleException(ErrFARetrieveFromDb)
End If
Finally
comGetBlob.Dispose()
End Try
End Function
 
G

Guest

I guess it would help if I explained the rest of the problem.

Upon executing this code I recieve a retval of "0" on the larger documents
as well as an Arithmetic Overflow Error.

Also I have tried multiple buffer sizes such as Integer.MaxValue, 8912, etc
etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top