Mike,
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=2001033101page=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
1600, 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=greenFile was successfully uploaded...
Response.Write /font
Else
Response.Write font color=brownNo 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=greenFile was successfully uploaded...
Response.Write /font
Else
Response.Write font color=brownNo 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 =