Article ID: 173308
Article Last Modified on 5/2/2006
FILE: SHOWIMG.ASP
<%@ LANGUAGE="VBSCRIPT" %>
<%
' Clear out the existing HTTP header information
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear
' Change the HTTP header to reflect that an image is being passed.
Response.ContentType = "image/gif"
Set cn = Server.CreateObject("ADODB.Connection")
' The following open line assumes you have set up a System DataSource
' by the name of myDSN.
'Remember to change the following connection string parameters to reflect the correct values
'for your SQL server.
cn.Open "DSN=myDSN;UID=<username>;PWD=<strong password>;DATABASE=pubs"
Set rs = cn.Execute("SELECT logo FROM pub_info WHERE pub_id='0736'")
Response.BinaryWrite rs("logo")
Response.End
%>
This script only displays an image on the screen. If you wish to
display an image from an HTML or ASP document you must refer to this script in
an image tag. For example, if you wished to display this image with a caption
describing it, you might use the following HTML page: <HTML> <HEAD><TITLE>Display Image</TITLE></HEAD> <BODY> This page will display the image New Moon Books from a SQL Server image field.<BR> <IMG SRC="SHOWIMG.ASP"> </BODY> </HTML>Note The ASP script assumes that the image field (BLOB Data) in the SQL Server table contains a raw GIF image. Internet browsers assume that raw GIF or JPEG data follow the HTTP header. If any extraneous information is contained in the BLOB data, this will be passed by this script, and the image will not display properly. This becomes important when you realize that most methods of placing images into BLOB fields place extra information in the form of headers with the image. Examples of this are Microsoft Access and Microsoft Visual FoxPro. Both of these applications save OLE headers in the BLOB field along with the actual binary data.
Keywords: kbhowto kbcodesnippet kbdatabase kbaspobj KB173308