Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Reading images stored as binary data

Author  Topic 

neovi
Starting Member

2 Posts

Posted - 2002-09-02 : 04:15:22
Hi to you all.
I'm trying to setting up an asp page that returns images stored in an SQL200 database as binary data [field type: image] and read by a view called "My View".
In order to doing that I wrote this asp page called "photo001.asp"


<%
Dim ID
ID = Request("ID")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open Application("MyConnection_ConnectionString")
Set rs = conn.Execute("SELECT [ID], [Photo001] FROM MyView WHERE ID = " & ID)
Response.ContentType = "image/jpeg"
Response.BinaryWrite (rs("Photo001"))
rs.Close
Set rs = Nothing
%>


The page "photo001.asp" is read from the following row written in the page "readphotos.asp":


<%Response.write "<img src=""photo001.asp?ID=" & fp_rs("ID") & """>"%>



Someone can tell me what I'm doing wrong?
Thanks for your cooperation.


ashok
Yak Posting Veteran

57 Posts

Posted - 2002-09-02 : 05:18:23
I have had problems with displaying excel files from a SQL db (again stored as a blob binary data) when I didnt use response buffering.

try doing this :

Response.Buffer = True
Response.Clear

at the starting of photo001.asp
and

Response.End

after the BinaryWrite method.

I also encountered similar problems in a case where access forms were being used in conjunction SQLServer tables - the problem with that was Access was appending additional headers to the blob information (the excel sheet) when access committed the information to SQL Server storage. THis meant that what was output by binaryWrite was not an excel file anymore...



Go to Top of Page

neovi
Starting Member

2 Posts

Posted - 2002-09-05 : 02:53:43
Thanks for your reply, ashok.
I'm sorry: it doesn't work.
The page "readphotos.asp" contains other data after the line

<%Response.write "<img src=""photo001.asp?ID=" & fp_rs("ID") & """>"%>

and if I follow your suggestion, I can read these datas no more.
Since I'm a newbie in asp, it could be wonderful to get other suggestions. Thanks for your collaboration.

Go to Top of Page

ashok
Yak Posting Veteran

57 Posts

Posted - 2002-09-06 : 11:51:44
Neovi :
quote:

The page "readphotos.asp" contains other data after the line

<%Response.write "<img src=""photo001.asp?ID=" & fp_rs("ID") & """>"%>




The response.buffer & response.end lines need not be there in readphotos.asp (readphotos.asp looks fine to me). you should try putting those lines in photo001.asp.

BTW how big is this image ? ASP has a performance problem rendering using binarywrite any thing that is above 5 megs.

Go to Top of Page
   

- Advertisement -