?
Solved

Ole Object in Access to SQL Server Image field Issue

Posted on 2006-07-06
7
Medium Priority
?
367 Views
Last Modified: 2013-11-25
Hello,

I am having the hardest time displaying an image from a SQL Server image field.  I used DTS to import the data from an Access 2000 database.  Nothing to crazy.  The field in Access was of type Ole Object, while the field in SQL Server is of type image.

I need to display this image field on a web page so I am assuming I need to transform it in a jpeg.  Below is the VB.NET code I wrote to perform this task.


            Try

                Dim streamIn As New System.IO.MemoryStream(objEmployee.Photo)
                Dim imgIn As Image = New Image.FromStream(streamIn)
               
             'will manipulate the image here to change height and width
               Dim streamOut As New MemoryStream
               Dim imgOut As Image
               imgOut = imgIn

               imgOut.Save(streamOut, Imaging.ImageFormat.Jpeg)
                Response.ContentType = "image/jpeg"
                Response.Write(imgOut)
                Response.End()
            Catch ex As Exception
                Throw New Exception(ex.Message)
            End Try

The object objEmployee.Photo is my custom data object and is of type Byte[].  An exception reading "Invalid Parameter Used" gets thrown on the line:

Dim imgIn As Image = New Image.FromStream(streamIn)

I don't know what I am doing wrong.  I DID notice in the Access database had the following information in the photo column when I viewed it in table view in Access.  Each row had one of the following pieces of information in it.  Does this inconsistency have anything to do with my problem?

Imgio.Document
MSPhotoEd.3
Bitmap Image
Microsoft Word Picture
ZoomBrowserImageServer.Document

Getting this to work will save a lot of time and face with my client.

Thank you,

Marc
 
0
Comment
Question by:throttlenet
[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
  • 4
  • 2
7 Comments
 
LVL 3

Expert Comment

by:reiss20
ID: 17055599
Hi throttlenet,

I would never suggest storing the actual image in the database, it uses up too much space, and seriously affects the performance of your application. Instead why don't you just save the path to the image?, this would be stored as a simple string.

Reiss :o)
0
 
LVL 1

Author Comment

by:throttlenet
ID: 17058586
I would if I could.  As I am aware of this as a best practice.  However, the Access database was what the customer gave me.  When I asked him if he had the original jpegs, he looked at my funny and told me that they didn't keep them.  So I will need to solve this problem by using this method.

Thanks,

Marc
0
 
LVL 13

Expert Comment

by:PraxisWeb
ID: 17058815
HOW TO: Read and Write BLOB Data by Using ADO.NET Through ASP.NET

http://support.microsoft.com/default.aspx?scid=kb;en-us;326502

0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 1

Author Comment

by:throttlenet
ID: 17060183
I tried rewriting my code so that it matches the listing in the MSDN article.  

Response.Buffer = True
Response.ContentType = "Image/JPEG"
Response.BinaryWrite(objEmployee.Photo)

It does not throw an exception, however the browser displays a broken image as if the image didn't exist.  

My custom data object is of type Byte[].  I will create a test that does not use my custom data object, but I am wonder if it has something to do with the data in the database.  Please look at the information referring to the different types of information in the Ole data field.

Imgio.Document
MSPhotoEd.3
Bitmap Image
Microsoft Word Picture
ZoomBrowserImageServer.Document

Are these going to give me any problems?

I will let you know if it is an issue with my custom data object.

Thanks,

Marc
0
 
LVL 13

Accepted Solution

by:
PraxisWeb earned 1000 total points
ID: 17072663
The data in the DB is a .BMP  and you are telling the browser to expect a JPEG.

IE does have the ability to show BMP files, however you would be best served by converting to a JPEG or GIF.

(http://www.codeproject.com/csharp/dotnet_convertimage.asp?df=100&forumid=4248&exp=0&select=999110) could give you a start... or you could set up a batch job with something like photoshop to convert all the items and re-save them into the db.

0
 
LVL 1

Author Comment

by:throttlenet
ID: 17082693
I will try this and post my results.  Thank you.
0
 
LVL 1

Author Comment

by:throttlenet
ID: 17100243
I tried the example on code project to write it to a file before converting it to a JPEG.  Still no luck.  I think it's a problem with the source data.  I think I have exhausted all options to extracting these ole objects.  I am going to have the client resize and resubmit the images to me in a better format.  

But I will admit I learned a lot about image processing during this thread. And because of that I will award you the points.

Thanks!
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

800 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