Access OLE Object through ASP

Posted on 2003-02-21
Medium Priority
Last Modified: 2007-12-19
I have created both the ASP page and the Access Database. The Access database has a field called picture with OLE Object as its Meta data. This field holds .jpg, .gif, or bitmap images. I can successfully connect to the database through the ASP page and run queries to the database. However when I ask it to return a picture from the database all I get is the word binary displayed as my result? The picture is in the database and I can view from the database. Has anyone tried this before and if so how did they do it? I have tried everything I can think of and nothing seems to work. Any help would be greatly appreciated.

Question by:rootdown_1
LVL 20

Accepted Solution

jitganguly earned 200 total points
ID: 7994325
Have your tried binarywrite ?

response.binarywrite rs("yourolecolumn")

Actually it is not a very good practice to store the image in a datbase for any web applications. You would rather put in a separate folder in your web server and point each of them with some id stored in database.


Author Comment

ID: 7995421
Here is my code:

sql = "select * from Name"
Set Conn = Server.CreateObject("ADODB.Connection")
Set RS   = Server.CreateObject("ADODB.RecordSet")
Conn.Open "Testpic"
RS.Open SQL, Conn
response.binarywrite rs("Picture")


It only returns:

  $     ÿÿÿÿPackagePackage    PackageK  1.Õ ÿØÿà JFIF    , ,ÿÛC                  &#64979;     $.' ",#  (7),01444'9=82<.342ÿÛC     2! !

And so on. It looks like it is trying to read it. Do you have any more suggestions?
LVL 25

Expert Comment

ID: 7996881
Storing your images as OLE objects and then trying to get them out will be a huge pain-- read that as next to impossible.

The problem is that when you use Insert OLE... the application registered to handle that file takes care of its actual binary storage format... so your jpegs may not be jpegs anymore.  The binary format that you end up storing isn't necessarily the same that you inserted-- depends upon the OLE server that's registered for that document.  For example, I have Corel PhotoPaint installed.  It takes of the OLE storage for my JPEGs and it doesn't necessarily keep them internally as a JPEG.  After using Insert Object, I've now got a Corel PhotoPaint "document" (OLE structured storage) in my Access database-- not a binary formatted jpeg.

Even if you're lucky enough to have your container application keep the binary format the same, you still have OLE header information tagged on to it.  So, you need to strip the OLE header information out.  There's an article with a BMP as an example on one of the ASP sites.  Can't remember exactly how many bytes you need to strip for a BMP (assuming your OLE Server is still PaintBrush for bitmaps... if it's not the amount of header may be different).  I can track down the article if you're really interested.

The trick to storing and using images from an Access database is to store them as BLOBs rather than OLE objects.  If you actually write the binary data directly into an OLE-type Access field (rather than using Insert Object), you end up with a BLOB rather than OLE structured storage.  Access will even tell you that.  It'll show up as in Access when you look at the field as BLOB.  You can binarywrite the BLOB and have it show up correctly.  If you want an example, let me know and I'll dig one up from a few years ago.

Most people will agree with jitganguly about it not being a good practice to store your images within the database, but rather store links to them.  I'm of the mind that it really depends upon the particular application and use whether it makes sense or not.  But, in general, they're right.  Just for performance purposes alone... IIS streams stuff from the file system a heck of lot faster than it'll spit out ASP streams.

Expert Comment

ID: 9576966
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.
LVL 58

Expert Comment

ID: 9754396
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Answer by jitganguly

Please leave any comments here within the next seven days.
EE Cleanup Volunteer

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
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…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

621 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