Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Thanked 0 Times in 0 Posts

    asp file upload script having problems with MYSQL

    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

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Near Chicago, IL, USA
    Thanked 32 Times in 31 Posts
    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.

    If you want the adovbs.inc file most people use to define constants, I have it here.

    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.

    Hope this helps.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Thanked 2 Times in 2 Posts
    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).
    J. Paul Schmidt
    www.Bullschmidt.com - Freelance Web and Database Developer
    www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts