Thank you very much for responding to my question. Haven't been able to find much out there. Your article, to which you referred in your response, was something I have already used to get me as far as I had gotten. I'd found it in my search for an answer. I found the connection string and the explanation of the options you used particularly useful. The comment you made about the cursor location confirmed what I read elsewhere, though put a different way. I've read that MySQL simply doesn't support cursors, so you have to set the cursor location to client. In the MySQL docs I've seen where they indicate that in the near future they plan to support cursors.
I was able to follow the example on stardeveloper.com (http://www.stardeveloper.com/articles/display.html?article=2001033101&page=1) for uploading files and inserting them into a database as described without trouble.
The troubles start when I try to adapt the example for use with MySQL instead of MS Access.
I can't for the life of me get it to work consistently. I have changed the cursor location to client, I have changed the max_allowed_packed to 16000000, I have swapped out the table names that you can use with Access with the complete select statements that MySQL requires. Still, when I try to upload a file larger than 1 MB I get the following error: "Microsoft OLE DB Provider for ODBC Drivers error '80040e21' [MySQL][ODBC 3.51 Driver][mysqld-4.0.5-beta-max-nt]Lost connection to MySQL server during query." Sometimes the error is: "Microsoft OLE DB Provider for ODBC Drivers error '80040e21' [MySQL][ODBC 3.51 Driver][mysqld-4.0.5-beta-max-nt]Got a packet bigger than 'max_allowed_packet'"
I'm sure the file is less than 2MB.
With this code:
' Checking to make sure if file was uploaded
If fileSize > 0 Then
set rsImage = Server.CreateObject("ADODB.Recordset")
rsImage.ActiveConnection = MM_connShooters_STRING
rsImage.Source = "select * from web_lab.Images limit 0"
rsImage.CursorType = adOpenKeyset
rsImage.CursorLocation = adUseClient
rsImage.LockType = adLockPessimistic
rsImage.Open()
rsImage_numRows = 0
' Adding data
rsImage.AddNew
rsImage("userID") = userID
rsImage("imageType") = contentType
rsImage("imageSize") = fileSize
rsImage("imageName") = fileName
rsImage("imageCaption") = caption
ERROR-->rsImage.Update
rsImage.Close
Set rsImage = Nothing
Response.Write "<font color=""green"">File was successfully uploaded..."
Response.Write "</font>"
Else
Response.Write "<font color=""brown"">No file was selected for uploading"
Response.Write "...</font>"
End If
When I adapt the code to use the Stream object instead of .AppendChunk, I get this error: "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another." The code for the insert is as follows:
' Checking to make sure if file was uploaded
If fileSize > 0 Then
set adoImageStream = Server.CreateObject("ADODB.Stream")
adoImageStream.Type = adTypeBinary
set rsImage = Server.CreateObject("ADODB.Recordset")
rsImage.ActiveConnection = MM_connShooters_STRING
rsImage.Source = "select * from web_lab.Images limit 0"
rsImage.CursorType = adOpenKeyset
rsImage.CursorLocation = adUseClient
rsImage.LockType = adLockPessimistic
rsImage.Open()
rsImage_numRows = 0
' Adding data
rsImage.AddNew
adoImageStream.Open
ERROR--> adoImageStream.Write fileData
rsImage("userID") = userID
rsImage("imageType") = contentType
rsImage("imageSize") = fileSize
rsImage("imageName") = fileName
rsImage("imageCaption") = caption
rsImage("imageData") = adoImageStream.read
rsImage.Update
adoImageStream.Close
rsImage.Close
Set rsImage = Nothing
Response.Write "<font color=""green"">File was successfully uploaded..."
Response.Write "</font>"
Else
Response.Write "<font color=""brown"">No file was selected for uploading"
Response.Write "...</font>"
End If
I'm almost sure this error arises because the class object used for the page (found on the site with the tutorial, called 'loader.asp') changes the binary form data to a string, so the stream of type adTypeBinary doesn't accept the data, but when I change the stream type to text then I get an error because the field is expecting binary data. I haven't found an efficient enough way to change the data back to binary or to alter the class so that it doesn't turn the file data into a string in the first place. The relevant code from the class is this subroutine, which gets called when the object is initialized, to parse the form data:
Private Sub getData(rawData)
Dim separator
separator = MidB(rawData, 1, InstrB(1, rawData, ChrB(13)) - 1)
Dim lenSeparator
lenSeparator = LenB(separator)
Dim currentPos
currentPos = 1
Dim inStrByte
inStrByte = 1
Dim value, mValue
Dim tempValue
tempValue = ""
While inStrByte > 0
inStrByte = InStrB(currentPos, rawData, separator)
mValue = inStrByte - currentPos
If mValue > 1 Then
value = MidB(rawData, currentPos, mValue)
Dim begPos, endPos, midValue, nValue
Dim intDict
Set intDict = Server.CreateObject("Scripting.Dictionary")
begPos = 1 + InStrB(1, value, ChrB(34))
endPos = InStrB(begPos + 1, value, ChrB(34))
nValue = endPos
Dim nameN
nameN = MidB(value, begPos, endPos - begPos)
Dim nameValue, isValid
isValid = True
If InStrB(1, value, stringToByte("Content-Type")) > 1 Then
begPos = 1 + InStrB(endPos + 1, value, ChrB(34))
endPos = InStrB(begPos + 1, value, ChrB(34))
If endPos = 0 Then
endPos = begPos + 1
isValid = False
End If
midValue = MidB(value, begPos, endPos - begPos)
intDict.Add "FileName", trim(byteToString(midValue))
begPos = 14 + InStrB(endPos + 1, value, stringToByte("Content-Type:"))
endPos = InStrB(begPos, value, ChrB(13))
midValue = MidB(value, begPos, endPos - begPos)
intDict.Add "ContentType", trim(byteToString(midValue))
begPos = endPos + 4
endPos = LenB(value)
nameValue = MidB(value, begPos, ((endPos - begPos) - 1))
Else
nameValue = trim(byteToString(MidB(value, nValue + 5)))
End If
If isValid = True Then
intDict.Add "Value", nameValue
intDict.Add "Name", nameN
dict.Add byteToString(nameN), intDict
End If
End If
currentPos = lenSeparator + inStrByte
Wend
End Sub
An effective solution to my problem lies either in what I'm doing wrong with MySQL (obviously I'm doing something wrong, else I wouldn't be getting errors using the AppendChunk method) or with converting the data into a binary type so it can be written to the adTypeBinary type Stream object.
At 05:01 PM 12/30/2002 -0700, you wrote:
Thank you,<BEGIN SHAMELESS PLUG> Hi Kevin;You may want to look at the online article I wrote at http://www.dynamergy.com/mike/articles/blobaccessvb.html which covers use of the stream object in detail. While written for VB, it should be easy enough to convert to ASP. Mike Hillyer <END SHAMELESS PLUG> -----Original Message----- From: Kevin Wixson [mailto:[EMAIL PROTECTED]] Sent: Monday, December 30, 2002 10:29 AM To: [EMAIL PROTECTED] Subject: Binary Data and BLOB Problem
Kevin Wixson
IT Manager
Norman Camera & Video
(616) 567-5552
1-800-900-6676
Fax: (616) 343-6410
e-mail: [EMAIL PROTECTED]
Visit us on the web at: http://www.normancamera.com
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php