View Full Version : asp file upload script having problems with MYSQL

09-20-2005, 11:57 AM
I am trying to connect to mysql db through asp with code that is to upload a file from a computer. I get this error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e21'

Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.

/uploadexmple.asp, line 47

I am using code that i got from http://www.asp101.com/articles/jacob/scriptupload.asp, a program by jacob gilley to upload files with asp. Heres the bit thats giving me problems

ElseIf Uploader.Form("saveto") = "database" Then

' Open the table you are saving the file to
dim rs
Set RS = Server.CreateObject("ADODB.Recordset")
RS.open "select * from lecnotes", "Driver={Mysql}; Server=mysql1.webhost.ie; Database=paulmc; UID=paul; PWD=1881 ",2,2
RS.AddNew ' create a new record

RS("filename") = file.filename
RS("filesize")= File.FileSize
RS("contenttype") = File.ContentType

' Save the file to the database
File.SaveToDatabase RS("filedata")

' Commit the changes and close
End If

lecnotes is the name of the table where i'll store the file and it has properties:

Field Type Attributes Null Default Extra Action
filename varchar(20)
filesize varchar(20)
contenttype varchar(40)
filedata blob BINARY

any help appreciated...thanks

09-20-2005, 03:21 PM
I would really use a connection object and the vb constants...

Set RS = Server.CreateObject("ADODB.Recordset")
RS.open "select * from lecnotes", "Driver={Mysql}; Server=mysql1.webhost.ie; Database=paulmc; UID=paul; PWD=1881 ",2,2

That's going to be very hard to modify later if you need to, and who knows what kind of cursor you're using...
Make a connection object, test its state first to be sure it's okay, THEN open the recordset with it.
Example code here (http://www.ipwebdesign.net/useful_aspquery.html).

If you want the adovbs.inc file most people use to define constants, I have it here (http://www.ipwebdesign.net/adovbs.inc).

That way, you can open the connection and set recordset properties however you want in more understandable english-like abbreviations, say:

(snippets of code I actually use in an application, with sensitive data xxx out)

Set objConn = Server.CreateObject("ADODB.Connection")
strConn = "Provider=sqloledb;" & _
"Data Source=xx.xx.xx.xx;" & _
"Initial Catalog=XXX;" & _
"User Id=xxxxx;" & _


objConn.ConnectionTimeout = 900
objConn.CommandTimeout = 900
objConn.Open strConn


objRS.Open strSQL, objConn, adOpenStatic,adLockReadOnly, 1

You can check the state of a connection using the state property (http://docs.sun.com/source/817-2514-10/Ch11_ADO36.html).

Hope this helps.

09-20-2005, 08:30 PM
Here's something similar I've done but here the uploaded file does NOT get saved in the database.

You can connect to a csv file (which can be opened in Excel and which an Excel file can be converted into) in good form just as you can to a regular database.

The .csv file needs to be uploaded to the server.

And you can have two recordsets open at the same time.

So I'd suggest going through this recordset one row at a time and within this loop add a new record to the "real" database's recordset.

And for help connecting to a text file using the Jet OLE DB provider:

And based on the above link realize that the actual filename does NOT go in the connection string - rather it goes in the SQL statement (definitely a little tricky).

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum