Syncing BLOB results in 0 byte file
196606Feb 27 2008 — edited Mar 4 2008Hello, I have a custom VB program that scans a driver's license. The face image and text are then saved to the OLite client DB. However, when I sync to the server, the BLOB field is 0 bytes in the target table.
I have based the handling of the BLOB in my program on the BLOB sample code that is delivered with the Oracle Lite sample code <ora lite home>\mobile\sdk\samples\ado.net\win32\blob. When I run that code, it writes to the mobile client DB and then re-queries the BLOB, as it should. In order to test this with the sync, I then modified that sample code so that it writes the BLOB to my own table rather than the sample table. I then run msync, and it is also 0 bytes on the server. Is this some bug or maybe some setup that is missing? The code below is the section that handles the BLOB inserting and reading. I hope someone can help ... thanks in advance!
ryan
++++++++++++++++++++++++++++++++++++++
Private Sub Run()
Dim conn As OracleConnection
' Create Database
'
SetDone(lblCreate, False)
' Open database connection
'
Dim dsn As String = "dsn=IDMAN32_" & "emready;uid=system;pwd=IDMAN32"
conn = New Oracle.DataAccess.Lite.OracleConnection(dsn)
conn.Open()
SetDone(lblCreate, True)
' Create a table with a blob column
'
Dim cmd As IDbCommand
Dim blob As OracleBlob
SetDone(lblTable, False)
cmd = conn.CreateCommand()
' Create new BLOB object in polite database
'
SetDone(lblInsert, False)
blob = New OracleBlob(conn)
'Read data from the image file and write it into the blob
'in chunks
'
Dim file As FileStream
Dim browse As System.Windows.Forms.OpenFileDialog = New System.Windows.Forms.OpenFileDialog
browse.Filter = "Bitmap (*.bmp)|*.bmp|Gif (*.gif)|*.gif"
browse.Title = "Choose an Image File"
browse.ShowDialog()
Dim imageSrc As String = browse.FileName
Dim imageDes As String = "tmp.gif"
If imageSrc Is Nothing Or imageSrc.Length = 0 Then
imageSrc = "oracle.gif"
End If
file = New FileStream(imageSrc, FileMode.Open, FileAccess.Read)
Dim ImageData As Byte()
ReDim ImageData(file.Length)
Dim ArraySize As Integer = New Integer()
ArraySize = System.Convert.ToInt32(file.Length)
file.Read(ImageData, 0, ArraySize)
file.Close()
' Insert our image blob into the table using LiteParameter
'
cmd.CommandText = "insert into EMPLOYEE_STAGING (EMPLOYEE_ID, PHOTO) values(11000, ?)"
cmd.Parameters.Add(New OracleParameter("Image", blob))
cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
conn.Commit() ' Commit transaction
SetDone(lblInsert, True)
' Read blob from the Database and write to a temp file
'
SetDone(lblRead, False)
Dim reader As IDataReader
cmd.CommandText = "select EMPLOYEE_ID, PHOTO from EMPLOYEE_STAGING WHERE EMPLOYEE_ID=11000"
reader = cmd.ExecuteReader()
If reader.Read() = False Then
cmd.Dispose()
conn.Close()
Throw New Exception("Failed to read blob")
End If
blob = reader.GetValue(1)
reader.Close()
file = New FileStream(imageDes, FileMode.Create, FileAccess.Write)
file.Write(ImageData, 0, ArraySize)
file.Close()
' Close database connection
'
conn.Close()
SetDone(lblRead, True)
' Display bitmap
'
Dim bmp As Bitmap
bmp = New Bitmap(imageDes)
bmpBox.Image = bmp
End Sub