How to see an image in db?

  • 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!

  • Did you try to use MS Access or other reporting services?

  • Ya know, it didn't even occur to me to try that. I'll give it a shot.

  • 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

  • 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.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • 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