I am using the LEADOLEDB (v10) object to store a TIF image in an Image database column (column type is image).
The code is based on the example in the Help file and works fine with Access, but when I moved the database to SQL Server, the DataSaved event is getting a 20005 error.
My code looks like this:
Private Sub AdodcImages_WillMove(ByVal adReason As ADODB.EventReasonEnum, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
On Error GoTo WillMoveError
If (gbDataDirty) Then
LEADOLEDBImages.Bitmap = 0
If (LEAD1.Bitmap > 0) Then
If LEAD1.BitmapBits = 1 Then
'Compressed TIF
LEADOLEDBImages.DataSaveBits = 1
LEADOLEDBImages.DataSaveFormat = FILE_CCITT_GROUP4
LEADOLEDBImages.DataSaveQuality = QFACTOR_QMS
Else
LEADOLEDBImages.DataSaveBits = 24
LEADOLEDBImages.DataSaveFormat = FILE_LEAD
LEADOLEDBImages.DataSaveQuality = QFACTOR_QMS
End If
'Prepare to write the image to the database column.
LEADOLEDBImages.Bitmap = LEAD1.Bitmap
LEADOLEDBImages.DataDirty = True
End If
End If
Exit Sub
WillMoveError:
ErrorMsgBox "Error in WillMove adding to Image Database: 0x" & Hex(err.Number) & " - " & err.Description
End Sub
Private Sub LEADOLEDBImages_DataLoaded(ByVal nStatus As Integer)
If (nStatus = 0) Then
LEAD1.RefBitmap = True 'don't make a copy
LEAD1.Bitmap = LEADOLEDBImages.Bitmap 'send the image to the LEAD OCX
LEAD1.RefBitmap = False 'reset
ElseIf (nStatus = ERROR_FILENOTFOUND) Then 'if it's an empty record
ElseIf (nStatus <> ERROR_FILENOTFOUND) Then 'if it's not an empty record
LEAD1.Bitmap = 0
If Not Adodc1.Recordset.EOF Then
ErrorMsgBox "Error " & nStatus & ":" & err.Number & " loading image from database: " & err.Description
End If
End If
gbDataDirty = False
End Sub
Private Sub LEADOLEDBImages_DataSaved(ByVal nStatus As Integer)
LEADOLEDBImages.Bitmap = 0 'free the current reference
If (nStatus <> 0) Then
LEAD1.ForceRepaint
ErrorMsgBox "Error " & nStatus & " saving to image database" & vbCrLf
End If
End Sub
MAIN CODE TO CREATE THE DATABASE RECORD:
AdodcImages.Recordset.AddNew
... set non-image database fields
AdodcImages.Recordset.Update 'create the record.
LEADOLEDBImages.Bitmap = 0
LEAD1.Load TIFFileName, 0, 0, 1
gbDataDirty = True
AdodcImages.Recordset.Filter = 0 'forces the output of the image field by triggering WillMove.
---> THIS CAUSES A 20005 ERROR IN DataSaved with SQL Server.
What causes these 20005 errors from the OLEDB control?
If there was an underlying SQL database error, how can I access the real error code?
Thanks for any help you can offer.