Solved

Ole Object in Access to SQL Server Image field Issue

Posted on 2006-07-06
7
362 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
  • 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
Independent Software Vendors: 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!

 
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

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

Suggested Solutions

Title # Comments Views Activity
Tracking uptime for a bunch of sites 3 75
Add a loading gif while php runs server side 15 67
Print a <div></div> only 5 40
calculate days away 11 31
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

730 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