Solved

Writing to BLOBs in mySQL and ASP

Posted on 2004-04-28
15
1,185 Views
Last Modified: 2012-08-13
I have transferred to a mySQL database and have run up against a problem.

I use the below code to create a new record but it cannot create the record due to an error caused by incorrect code when writing to a BLOB.

Response.Buffer = true
set rst = Server.CreateObject("ADODB.RecordSet")
sqltext = "SELECT * FROM TableName"

rst.Open sqltext,objaConn,3,3
rst.AddNew
rst("name") = Request.form("name")' varchar in DB
rst("email") = Request.form("email") ' varchar in DB
rst("information") = Request.form("information") 'blob in DB
rst.update
rst.close
0
Comment
Question by:BeakerTrail
  • 8
  • 6
15 Comments
 
LVL 11

Expert Comment

by:Slimshaneey
Comment Utility
Change the code to

rst.Open sqltext,objaConn,3,3
rst.AddNew
rst("name") = Request.form("name")' varchar in DB
rst("email") = Request.form("email") ' varchar in DB
rst("information").AppendChunk = Request.form("information") 'blob in DB
rst.update
rst.close
0
 

Author Comment

by:BeakerTrail
Comment Utility
That returns an error:

ADODB.Field error '800a0c93'

Operation is not allowed in this context.

line 95 <-- line with appendchunk on.
0
 
LVL 31

Expert Comment

by:alorentz
Comment Utility
Not sure about this: ($)

Response.Buffer = true
sqltext = "INSERT INTOP TableName (name, email, information) VALUES " & _
    "('" & request("email") & "', '" & request("email") & "', '$" & request("information") & "')"

objaConn.execute sqltext
0
 
LVL 31

Expert Comment

by:alorentz
Comment Utility
Whoops...think that was PHP, didn't read enough ;-)
0
 

Author Comment

by:BeakerTrail
Comment Utility
Yeah. What I am trying to do is in ASP - i've zero knowledge of PHP
0
 
LVL 31

Expert Comment

by:alorentz
Comment Utility
However, I would like to recommend not storing the image in the DB, rather store the path to the uploaded fileonthe server, then use this to display:

<img src="<%=rs("information")%>">
0
 
LVL 31

Expert Comment

by:alorentz
Comment Utility
Try this:

rst.Open sqltext,objaConn,3,3
rst.AddNew
rst("name") = Request.form("name")' varchar in DB
rst("email") = Request.form("email") ' varchar in DB
rst("information").AppendChunk Request.form("information") 'no = sign
rst.update
rst.close
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:BeakerTrail
Comment Utility
It isn't an image, it is a very big chunk of text.

The error i get occurs when writing to a Blob or a Text field. This is ASP and mySQL

I will post all the code below with the mySQL field types, maybe it will help:

Dim rst, objaConn, objaRS
Set objaConn = Server.CreateObject("ADODB.Connection")
objaConn.Open "Driver={MySQL ODBC 3.51 Driver};Server=xxx;Database=xxx;UID=xxx;PWD=xxx;"
Response.Buffer = true
set rst = Server.CreateObject("ADODB.RecordSet")
sqltext = "SELECT * FROM TableName"
rst.Open sqltext,objaConn,3,3
rst.AddNew
rst("name") = Request.form("name") 'varchar
rst("email") = Request.form("email") 'varchar
rst("datejoined") = Year(Date) & "-" & Month(Date) & "-" & Day(Date) & " " & time 'datetime
rst("information") = Request.form("information") 'text
rst("interests") = Request.form("interests") 'text
rst("occupation") = Request.form("occupation") 'text
rst.update 'line 114
rst.close

which gives the error:

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Driver Manager] Invalid string or buffer length

line 114
0
 

Author Comment

by:BeakerTrail
Comment Utility
For the line:
rst("information").AppendChunk Request.form("information")

It gives:

ADODB.Field error '800a0c93'

Operation is not allowed in this context.
0
 
LVL 31

Expert Comment

by:alorentz
Comment Utility
May need to put this in there:


Set objaConn = Server.CreateObject("ADODB.Connection")
objaConn.Open "Driver={MySQL ODBC 3.51 Driver};Server=xxx;Database=xxx;UID=xxx;PWD=xxx;"

objaConn.CursorLocation = adUseClient  '<---------ADD THIS

0
 

Author Comment

by:BeakerTrail
Comment Utility
That returns:

ADODB.Connection error '800a0bb9'

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
0
 
LVL 31

Accepted Solution

by:
alorentz earned 250 total points
Comment Utility
This then:

Set objaConn = Server.CreateObject("ADODB.Connection")
objaConn.CursorLocation = 3                           '<-----move line here and change to 3
objaConn.Open "Driver={MySQL ODBC 3.51 Driver};Server=xxx;Database=xxx;UID=xxx;PWD=xxx;"

Also, make sure you put back to this:

rst("information") = Request("information") '<-----should be fine for TEXT field


0
 
LVL 31

Expert Comment

by:alorentz
Comment Utility
Also, check the request object for data at top of page:

Response.write "TEXT: " & request("information")
Response.end
0
 

Author Comment

by:BeakerTrail
Comment Utility
Excellent! that did the trick, i think.... mySQL server keeps going down - argh!

Thanks :)
0
 
LVL 31

Expert Comment

by:alorentz
Comment Utility
MySQL is sketchy like that....good luck!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

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 would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

10 Experts available now in Live!

Get 1:1 Help Now