Long Raw Type Mismatch error

S

Sean

I'm new to using long raw fields with ASP. I know it would be easier
to leave the files on the file system, but the client wants them in
the database. Based on what I've read so far, I have used the
following code to read files from a hard drive and stuff them in the
database.

<%

'====================================================================================
'Function to read a binary file from disk
Function ReadBinaryFile(FileName)
Const adTypeBinary = 1

'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")

'Specify stream type - we want To get binary data.
BinaryStream.Type = adTypeBinary

'Open the stream
BinaryStream.Open

'Load the file data from disk To stream object
BinaryStream.LoadFromFile FileName

'Open the stream And get binary data from the object
ReadBinaryFile = BinaryStream.Read
End Function

'====================================================================================
' MAIN

dim objConn
DBObjConn() 'Open database


Set RS = CreateObject("ADODB.Recordset")
SQL = "SELECT * FROM pictures WHERE 1=0"

objConn.beginTrans

RS.Open SQL, objConn, adOpenKeyset, adLockOptimistic, adCmdText

Set FileSystem=CreateObject("Scripting.FileSystemObject")
root = Request.ServerVariables("APPL_PHYSICAL_PATH")
rootFilePath = root & "IQInputSource\crt_AGT1500"
filepath = FileSystem.GetAbsolutePathName(rootFilePath)
Set folder=FileSystem.GetFolder(filepath)
Set objFileList = folder.Files

for each objFile in objFileList
filename = objFile.Name
gfxSpex objFile.Path, width, height, depth, filetype
If InStrRev( LCase(filename), ".gif" ) OR InStrRev( LCase(filename),
".jpg" ) THEN
partnumber = Left(filename, InStr(filename,".")-1 )
RS.AddNew
RS("vcpartnumber") = partnumber
RS("width") = width
RS("height") = height
RS("vcfiletype") = filetype
RS("imagedata").appendChunk( ReadBinaryFile(objFile.Path) )
RS.update
End If
next

RS.close

objConn.commitTrans
%>


This seems to work fine, however, when I try and pull the images out
again, it doesn't always work. Some images come out and display just
fine others give me the following error.

error 'ASP 0106 : 80020005'
Type Mismatch, line 18
An unhandled data type was encountered.

Why would I get this only with some rows and not all of them? I
thought maby file size had something to do with it, but after doing
some checking, that doesn't seem to be the case. The code I'm using to
retrieve the data is pretty much straight from Microsoft's site.

<%
dim objConn
DBObjConn() 'Open database

id = Request.QueryString("id")

cmdsql = "SELECT imagedata, vcfiletype from pictures WHERE
vcpartnumber ='"&id&"'"
set rs = Server.CreateObject("adodb.Recordset")
rs.open cmdsql, objConn

Response.ContentType = "image/" & rs("vcfiletype")

Response.Expires = 0
Response.Buffer = TRUE
Response.Clear

temp = rs("imagedata")
Response.BinaryWrite temp
Response.End
%>


Any help is greatly appreciated.

-Sean
 

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

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top