Solved

Ole Object in Access to SQL Server Image field Issue

Posted on 2006-07-06
7
350 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 1

Author Comment

by:throttlenet
Comment Utility
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
Comment Utility
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
Comment Utility
I will try this and post my results.  Thank you.
0
 
LVL 1

Author Comment

by:throttlenet
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now