problems uploading files  to SQL database

Posted on 2004-11-19
Last Modified: 2008-02-20
I am trying to use a script to uplad word docs to a database using a script I found on the net.  however I keep getting an error msg I can't get past

Microsoft Cursor Engine error '80040e21'

Multiple-step operation generated errors. Check each status value.

/webpublishing/publishing/db-file-to-binary.asp, line 96

The scipt is below

<%@ Language=VBScript %>
<% option explicit %>
<%Response.Expires = 0
Response.CacheControl = "no-cache"%>

'Simple upload to database.
'Suitable for small files - up to 20% of physical server memory
'This sample works with any objDBConection - MDB (JetOLEDB, ODBC)

Server.ScriptTimeout = 240
'Simple upload to database

'Create upload form
'Using Huge-ASP file upload
'Dim Form: Set Form = Server.CreateObject("ScriptUtils.ASPForm")
'Using Pure-ASP file upload
Dim Form: Set Form = New ASPForm %><!--#INCLUDE FILE="_upload.asp"--><%

Server.ScriptTimeout = 1000
Form.SizeLimit = 1024*1024'1MB

'was the Form successfully received?
Const fsCompletted  = 0

If Form.State = fsCompletted Then 'Completted

  'Open objDBConection to database
Dim objDBCon, objDBRSExample, RS
Dim      strConnectionString
Dim strSQLstmt
strConnectionString = "Provider=SQLOLEDB;Data Source=CVNT158;Initial Catalog=WebPublishing;Integrated Security=SSPI"
'Only opent the objDBConection at the point where you need it!
Set objDBCon = Server.CreateObject("ADODB.Connection")
objDBCon.CursorLocation = 3 'Read/write cursor
objDBCon.Open strConnectionString
Set RS = Server.CreateObject("ADODB.RecordSet")
'Ideally use stored procedure and the ADO Command object - speak to me if you need examples of these however
'to illustrate the objDBConection works ok...
strSQLstmt = "SELECT * FROM WebPublishing.dbo.upload" strSQLstmt, objDBCon, 3 , 3


    'Store extra form info.
    RS("Description") = Form("Description")
    RS("Title") = Form("Title")

    'Add file from source field 'SourceFile' to table field 'Data'
     RS("Data") = Form("SourceFile").ByteArray

            'Some OLEDB drivers (Oracle) requires AppendChunk method
            'Please use next line instead of 'RS("Data") = Form("SourceFile").ByteArray'
   'RS("Data").AppendChunk Form("SourceFile").ByteArray

            'One-block assigning/AppendChunk is suitable for small files
            '(<20% physical server memory). Plese see documentation to store
            '10th megabytes or more in database.

    'Store technical informations
    RS("ContentType") = Form("SourceFile").ContentType
    RS("SourceFileName") = Form("SourceFile").FileName
    RS("DataSize") = Form("SourceFile").Length

    RS("UploadDT") = Now()
      response.write "<Font color=green><br>File " & Form("SourceFile").FileName & " (" & Form("SourceFile").Length & "B) was stored to a database"
  response.write "<br>See Upload table in " & Server.MapPath("upload.mdb") & " database.<br><br></Font>"
ElseIf Form.State > 10 then
  Const fsSizeLimit = &HD
  Select case Form.State
            case fsSizeLimit: response.write  "<br><Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font><br>"
            case else response.write "<br><Font Color=red>Some form error.</Font><br>"
  end Select
End If'Form.State = 0 then

Function GetConnection()
  dim objDBCon, strConnectionString : Set objDBCon = Server.CreateObject("ADODB.Connection")
  GetConnection = "Provider=SQLOLEDB;Data Source=CVNT158;Initial Catalog=WebPublishing;Integrated Security=SSPI"
  set GetConnection = objDBCon
  objDBCon.CursorLocation = 3 'Read/write cursor

end function

function CreateUploadTable(Conn)
  'This function creates upload table for MSSQL 6.5/7.0/2000
  dim SQL
  SQL = SQL & "CREATE TABLE Upload ("
  SQL = SQL & "      UploadID int IDENTITY (1, 1) NOT NULL ,"
  SQL = SQL & "      UploadDT datetime NULL ,"
  SQL = SQL & "      RemoteIP char (15) NULL ,"
  SQL = SQL & "      ContentType char (64) NULL ,"
  SQL = SQL & "      SouceFileName varchar (255) NULL ,"
  SQL = SQL & "      Title varchar (255) NULL ,"
  SQL = SQL & "      Description text NULL ,"
  SQL = SQL & "      Data image NULL "
  SQL = SQL & ")"
  objDBCon.Execute SQL
end function


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 <TITLE>ASP huge file upload sample.</TITLE>
 <STYLE TYPE="text/css"><!--TD      {font-family:Arial,Helvetica,sans-serif }TH      {font-family:Arial,Helvetica,sans-serif }TABLE      {font-size:10pt;font-family:Arial,Helvetica,sans-serif }--></STYLE>
 <meta name="robots" content="noindex,nofollow">
<BODY BGColor=white>

<Div style=width:600>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
    <TH noWrap align=left width="20%" bgColor=khaki>&nbsp;<A
      href="">Power ASP
      file upload</A> - upload to database, store file to binary data field&nbsp;</TH>
<TABLE cellSpacing=2 cellPadding=1 width="100%" bgColor=white border=0>
    <TD colSpan=2>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This sample demontrates using
      of Huge-ASP file upload to store files in server-side database.
                  The sample ASP file is running with Microsoft.Jet.OLEDB (MDB) objDBConection, but you can use it
                  with any other SQL server or file drivers (MS SQL server, Oracle, MySQL, FoxPro driver, etc.).

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;You can select source file, write some title and description of the file.
Title, description, file name, file size and file contents are stored in server-side database along with current upload time.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Form size limit is <%=Form.SizeLimit%>B (<%=Form.SizeLimit \ 1024 %>kB - you can change it, see source) .

<TABLE cellSpacing=1 cellPadding=3 bordercolor=silver bgcolor=GAINSBORO width="" border=1>
<form method=post ENCTYPE="multipart/form-data">
 <TD Align=Right><input type="submit" Name="Action" value="Upload the file &gt;&gt;"></TD>
 <TD>File to upload</TD>
 <TD><input type="file" name="SourceFile"></TD>
 <TD><input size="60" name="Title" value="Title of the file."></TD>
 <TD><textarea cols="60" rows="8" name="Description">Type description of the file.</textarea></TD>


<HR COLOR=silver Size=1>
<FONT SIZE=1>© 1996 – <%=year(date)%> Antonin Foller, <a href="">Motobit Software</a>, e-mail <A href="" ></A>
<br>To monitor current running uploads/downloads, see <A Href="">IISTracer - IIS real-time monitor</A>.

Question by:garthpyper
    LVL 4

    Expert Comment

    Try removing this line:

    objDBCon.CursorLocation = 3 'Read/write cursor

    Author Comment

    now it is not displaying an error, nor is it working
    LVL 75

    Accepted Solution

    The GetChunk/AppendChunk methods have been largely deprecated in favor of the Stream object introduced with ADO v2.5.

    Use this code (untested):

    Sub AddImage(rs, ByVal FileName)
    Dim stm

    Set stm = Server.CreateObject("ADODB.Stream")
    With stm
      .Type = adTypeBinary
      .LoadFromFile FileName
      'Insert the binary object into the table.
      rs.Fields("Data").Value = .Read
    End With
    Set stm = Nothing

    End Sub

    You would call this procedure as follows:

    Dim rs

    Set rs = Server.CreateObject("ADODB.Recordset")
    With rs
       .ActiveConnection = MY_CONN_STRING
       .Source = "SELECT Data FROM WebPublishing.dbo.upload Where 1=0"
       .CursorType = adOpenForwardOnly
       .LockType = adLockOptimistic
       .Open ,,,, adCmdText
       AddImage rs, FileName
    End With
    Set rs = Nothing

    As you can see it is a lot simpler.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
    I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now