January 25, 2008 at 9:56 am
I'm looking at a database, and there is a table with a column of image data type. Is there a way to view the images without having to write an app to pull it out?
Thx!
January 25, 2008 at 11:03 am
Did you try to use MS Access or other reporting services?
January 25, 2008 at 11:08 am
Ya know, it didn't even occur to me to try that. I'll give it a shot.
January 25, 2008 at 11:09 am
I'm not aware of any functionality built-in to SSMS to let you do that. But with very little code you can use the functionality built-in to a web browser to display them. The following is an ASP.NET example that displays JPEG's by setting the MIME type.
You may want to consider using VARBINARY(MAX) instead of the IMAGE data type since IMAGE looks like it will be removed in the future versions of SQL server.
' ASP.NET / VB.NET example
' Column definitions in MyTable are:
' image_field VARBINARY(MAX)
' imageid INT PRIMARY KEY
'
Dim strSQL As String = "SELECT [image_field] FROM MyTable WHERE imageid = intID "
Dim myCommand As SqlCommand(strSQL, myConn)
myConn.Open()
Dim myDataReader As SqlDataReader = myCommand.ExecuteReader
If myReader.Read Then
Response.ContentType = "image/jpeg"
Response.BinaryWrite(myReader("image_field")
End If
January 25, 2008 at 12:19 pm
If I'm not mistaken (someone correct me if I am), the Image datatype is actually stored in the DB as a binary file. Therefore, there is no good way to view it in the database. You literally have to have something "translate" the image before you can see it, and that requires a tool outside of SSMS.
Though SSRS as someone suggested might be just the tool to do it.
January 25, 2008 at 12:23 pm
I used Todd's quick and dirty ASP.NET code, and it worked like a charm.
Thank you all!
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply