G
Guest
I can write and read jpeg images to/from MS Access table BLOB fields using
the ReadBlob and Write Blob functions recommended in
http://support.microsoft.com/?kbid=210486, and the retrieved image can be
displayed in an MS access form image field.
If I connect to the Access database from an ASP page and read the BLOB field
using ADO.NET functions the returned file is twice the size of the file
returned when reading the BLOB field using MS Access, and it cannot be
displayed.
The code for reading the BLOB field is listed below and copied from
http://support.microsoft.com/default.aspx?scid=kb;en-us;326502 .
Can you suggest what may be causing this problem.
Comparing the contents of the two jpeg files returned it appears that each
byte in the original file is converted to two bytes when stored in the MS
access table. If the data is read back using the MS access WriteBLOB function
then each pair of bytes is correctly reconverted back to one byte with the
original value.
When the BLOB is read from the ASP page this does not happen. I tried
removing the most signifant byte of each pair of bytes and creating a file of
the original size but the picture could still not be displayed.
Further examination of the file contents showed that the most of the least
significant bytes of each pair contained the original value but occasionally
they did not and there is a value in the most significant byte.
<%@ Page Language="VB" Debug="true" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.IO" %>
<%
Dim PictureCol As Integer = 0 ' the column # of the BLOB field
Dim cn As New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Inetpub\wwwroot\PaulsWebASPNet\LakeDistrictFells2000.mdb")
Dim cmd As New OleDbCommand("SELECT photo FROM tblPhoto WHERE
PhotoNumber=2", cn)
cn.Open()
Dim dr As OleDbDataReader = cmd.ExecuteReader()
dr.Read()
Dim b(dr.GetBytes(PictureCol, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte
dr.GetBytes(PictureCol, 0, b, 0, b.Length)
dr.Close()
cn.Close()
‘***** start of temporary code ******
Dim fs As New
System.IO.FileStream("C:\Inetpub\wwwroot\paulsWebaspNet\test2.jpg",
IO.FileMode.Create, IO.FileAccess.Write)
fs.Write(b, 0, b.Length)
fs.Close()
‘***** end of temporary code ******
'Response.Expires = 0
'Response.Buffer = TRUE
'Response.Clear
'Response.ContentType = "image/jpg"
'Response.BinaryWrite(b)
'Response.End
%>
the ReadBlob and Write Blob functions recommended in
http://support.microsoft.com/?kbid=210486, and the retrieved image can be
displayed in an MS access form image field.
If I connect to the Access database from an ASP page and read the BLOB field
using ADO.NET functions the returned file is twice the size of the file
returned when reading the BLOB field using MS Access, and it cannot be
displayed.
The code for reading the BLOB field is listed below and copied from
http://support.microsoft.com/default.aspx?scid=kb;en-us;326502 .
Can you suggest what may be causing this problem.
Comparing the contents of the two jpeg files returned it appears that each
byte in the original file is converted to two bytes when stored in the MS
access table. If the data is read back using the MS access WriteBLOB function
then each pair of bytes is correctly reconverted back to one byte with the
original value.
When the BLOB is read from the ASP page this does not happen. I tried
removing the most signifant byte of each pair of bytes and creating a file of
the original size but the picture could still not be displayed.
Further examination of the file contents showed that the most of the least
significant bytes of each pair contained the original value but occasionally
they did not and there is a value in the most significant byte.
<%@ Page Language="VB" Debug="true" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.IO" %>
<%
Dim PictureCol As Integer = 0 ' the column # of the BLOB field
Dim cn As New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Inetpub\wwwroot\PaulsWebASPNet\LakeDistrictFells2000.mdb")
Dim cmd As New OleDbCommand("SELECT photo FROM tblPhoto WHERE
PhotoNumber=2", cn)
cn.Open()
Dim dr As OleDbDataReader = cmd.ExecuteReader()
dr.Read()
Dim b(dr.GetBytes(PictureCol, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte
dr.GetBytes(PictureCol, 0, b, 0, b.Length)
dr.Close()
cn.Close()
‘***** start of temporary code ******
Dim fs As New
System.IO.FileStream("C:\Inetpub\wwwroot\paulsWebaspNet\test2.jpg",
IO.FileMode.Create, IO.FileAccess.Write)
fs.Write(b, 0, b.Length)
fs.Close()
‘***** end of temporary code ******
'Response.Expires = 0
'Response.Buffer = TRUE
'Response.Clear
'Response.ContentType = "image/jpg"
'Response.BinaryWrite(b)
'Response.End
%>