SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


View image stored in VARBINARY(MAX) column in SQL SERVER 2008


View image stored in VARBINARY(MAX) column in SQL SERVER 2008

Author
Message
anonymous2009
anonymous2009
SSC-Enthusiastic
SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)

Group: General Forum Members
Points: 196 Visits: 175
Hello,

How to select and view the .jpg image stored in VARBINARY(MAX) column in SQL SERVER 2008?

Thanks!
Evil Kraig F
Evil Kraig F
SSC-Insane
SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)

Group: General Forum Members
Points: 20493 Visits: 7660
Inside of SQL Server? You don't, it doesn't render binaries to native format for you.

You'll need to extract it again back to its native format and then use other software/plugins/the front end that dropped it off to see it.

Is that what you're asking how to do? Extract it back to a .jpg file?


- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
anonymous2009
anonymous2009
SSC-Enthusiastic
SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)

Group: General Forum Members
Points: 196 Visits: 175
Exactly, that is what I was asking for.
Can you please explain to me on how exactly to achieve that?
Which tool should I be using?

Thanks!
math martinez
math martinez
Valued Member
Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)

Group: General Forum Members
Points: 65 Visits: 62
it depends on how the image stored.
if you insert it as byte then you need to retrieve and convert it into bitmap:-)
Evil Kraig F
Evil Kraig F
SSC-Insane
SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)

Group: General Forum Members
Points: 20493 Visits: 7660
Anon, Holidays ate me for a while, apologies. Did you still need help with this? How did the files get loaded to this in the first place?


- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
anonymous2009
anonymous2009
SSC-Enthusiastic
SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)

Group: General Forum Members
Points: 196 Visits: 175
Image was inserted into the table using simple UPDATE statement of actual VARBINARY value which I got from another table.
Not sure how the image was inserted into that table to begin with.
There is a free software called SSMSBoost which is an extension for SSMS.
This allows to view the image right from SSMS.

Another way to view the image is to export it from table to file system using bcp command.
Below link explains how to do that:
http://madhuottapalam.blogspot.com/2008/08/creating-files-from-images-stored-in.html

Thanks everybody!
Sean Lange
Sean Lange
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62321 Visits: 17954
I think the important concept here is that you want to view it, that means it is in the front end. It relatively trivial to do this in .NET or any number of other programming languages. The basic gist is that when you select the binary column you are returned a byte array. Then you just need to assemble that byte array into something usable by your presentation layer.

Here is an example of this in C# from some of our web code. In this particular case it is only dealing with images and I have a column that stores the ContentType. In my case I don't bother with the original file name because these are streamed directly to the response and never intended to be saved. You could some sort of method for determining which type of image you may have. If you have the filename stored that would be a good place to start.



DataTable dt = Some method to fill your datatable here

if (dt.Rows.Count > 0)
{
if (dt.Rows[0]["Image"] != DBNull.Value)
{
Bitmap bmp = new Bitmap(new MemoryStream((byte[])(dt.Rows[0]["Image"])));
if (bmp == null)
{
Response.Clear();
Response.StatusCode = 404;
Response.End();
return;
}

Response.ContentType = dt.Rows[0]["ContentType"].ToString();
if (dt.Rows[0]["ContentType"].ToString() == "image/gif")
{
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
}
else
{
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
bmp.Dispose();
}
}



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search