Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASPSmartUpload file.FileToField problem!!!!!!

Posted on 2003-10-28
4
Medium Priority
?
2,243 Views
Last Modified: 2011-10-03
HI could you tell me what is the problem with my code below?

****************************************
<%
Set uPBinaryFile = Server.CreateObject("aspSmartUpload.SmartUpload")
uPBinaryFile.Upload

set dbConn = Server.CreateObject("ADODB.Connection")
dbConn.Open = "Driver={mySQL ODBC 3.51 Driver};Server=kenneth;database=ecep;uid=root;pws=123456"

set rs = Server.CreateObject("ADODB.Recordset")
sql = "select image,filename,imagetype from mainpage_layout"
Set rs.ActiveConnection = dbConn
rs.Source = sql
rs.LockType = 3
rs.Open
For each file In uPBinaryFile.Files
            If not file.IsMissing Then      
      rs.AddNew            
            file.FileToField rs.Fields("image") <--- LINE 19
            rs("FileName") = file.filename
            rs("ImageType") = file.ContentType                                                
            rs.update
            intCount = intCount + 1
      end if
Next
%>
<%
rs.Close
dbConn.Close
Set rs = Nothing
Set dbConn = Nothing
%>
******************************************

Error Mesg :
ADODB.Field error '800a0c93'
Operation is not allowed in this context
uploadsave.asp, line 19

LINE 19 IS "file.FileToField rs.Fields("image")"

I'm using MySQL. FYI, Access and Ms SQL 2000 are working and it only happened when i use MySQL

image datatype  = "longblob"

If I comment line 19 it work correctly

Please advice ....
0
Comment
Question by:kennethcky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 6

Accepted Solution

by:
Programming_Gal earned 400 total points
ID: 9640287
1) If you are using an ADODB.Recordset to UPDATE / INSERT (e.g. using the AddNew method), use a direct SQL statement instead

A quick note: NEVER store a recordset in the session object. For a discussion of this see:
 
http://www.microsoft.com/mind/1198/ado/ado.htm 
http://support.microsoft.com/?kbid=176056

Most data access tasks can be implemented by using the execute method of the connection object. Why would we want to do this? Well, for one, there is extra overhead in using a recordset object for UPDATE and INSERT functionality. This is because the provider has to translate your code into an equivalent T-SQL statement anyway (the database itself has no knowledge of "addNew" and similar methods). Also, there are many dangerous locks associated with recordsets... most of which are not necessary (especially when performing an INSERT or UPDATE). Your goal should be to get in, tweak your data, and get out as quickly as possible. Using direct statements is the quickest way to do this, since there is much less overhead and no locks associated with your activity.
 
Another benefit of using an INSERT or UPDATE statement is that it is much easier to debug. You can change conn.execute(sql) to response.write(sql) and immediately see why your statement is throwing an error. With a multi-line transaction using a recordset object, it is translated to an INSERT or UPDATE statement (inefficient!) on the DB side, so there is no straightforward way to trap errors at the code level.
 
To use the connection object, simply design a transact-SQL statement for the action you want to use and implement it like so:
 
<%
    sql = "INSERT INTO <table> (fields) VALUES (values)"
    set conn = Server.CreateObject("ADODB.Connection")
    conn.open "<connection string>"
    conn.execute sql, , 129
    ' 129 is the constant for adExecuteNoRecords + adCmdText
    ...
%>
0
 
LVL 6

Expert Comment

by:Programming_Gal
ID: 9640308

<%
    sql = "EXEC SP_doSomething @param1=1, @param2='" & var & "'"
    set conn = Server.CreateObject("ADODB.Connection")
    conn.open "<connection string>"
    set rs = conn.execute(sql)
    ...
%>
0
 
LVL 6

Expert Comment

by:Programming_Gal
ID: 9640314
2) If you are trying to binaryWrite image data to an ASP page that also has plain text content, consider retrieving this data in a separate file and pointing to it via <IMG SRC>. You can also see http://support.microsoft.com/?kbid=276488 for ways to use ADODB.Stream to return binary content from a database, without using the GetChunk method.
0
 

Expert Comment

by:JimboDS
ID: 10615778
When using aspSmartUpload with the same type of setup as initially stated by 'kennethcky', I found I needed to set the cursor location to client in order to upload images and files to MySQL.  I set this in the connection object and all seemed to work fine.

objConn.CursorLocation = 3      'adUseClient

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

688 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