Solved

Ole Object in Access to SQL Server Image field Issue

Posted on 2006-07-06
7
365 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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
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 500 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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The viewer will learn how to dynamically set the form action using jQuery.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

707 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