Solved

Ole Object in Access to SQL Server Image field Issue

Posted on 2006-07-06
7
353 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

810 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