Good Afternoon,

I wrote a program that stores images into a mysql database blob field. I'm now trying to retrieve that image, I'm having zero luck. We use a scanner that save images as .tif files. I have the following code I'm trying, what do you see wrong?

Any help would be great!!


Dim FileSize As UInt32
Dim rawData() As Byte

Dim conn As MySqlConnection = clsData.OpenMySqlConnection()
Dim reader As MySqlDataReader = Nothing

Dim cmd As New MySqlCommand("SELECT image, filesize FROM scans WHERE ocrid = ?autoid", conn)
cmd.Parameters.AddWithValue("?autoid", strCheckNumber)

reader = cmd.ExecuteReader
reader.Read()

'data is in memory
FileSize = reader.GetUInt32(reader.GetOrdinal("filesize"))
rawData = New Byte(FileSize) {}

'get the bytes and filesize
reader.GetBytes(reader.GetOrdinal("image"), 0, rawData, 0, FileSize)

Dim ms As New System.IO.MemoryStream(FileSize)
ms.Write(rawData, 0, FileSize)

Dim im As Image = Image.FromStream(ms) '* "error occurs here" '(see below)
'pb.Image = im

Dim fs As New FileStream _
("c:\Temp\" & strCheckNumber & ".tif", FileMode.OpenOrCreate, _
FileAccess.Write)
fs.Write(rawData, 0, FileSize)
fs.Close()

Process.Start("\\tsa-acctmysql\scans\Temp\" & strCheckNumber & ".tif")

reader.Close()
conn.Close()
conn.Dispose()
ms.Dispose()