Unable to download BLOB IMAGE using ODBC

Clicking download link returns Item Cannot be found error

Page 1 of 1

2 Replies - 6025 Views - Last Post: 05 February 2007 - 06:23 PM Rate Topic: -----

#1 bananularstyle   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-December 06

Unable to download BLOB IMAGE using ODBC

Post icon  Posted 23 January 2007 - 07:45 AM

Hi everyone,

This is an issue I have been picking away at for the last week now and running short of ideas. :-\
Right now I am working on an ASP page that allows a user to open a tif image stored on SQL Server .
Thus far I have seen almost every error IE can throw back at me but, I think I've made some progress since
my first 20 attempts.

The link in my search results page calls a getAttachment.asp page (code listed below)
, which connects to the SQL Server through an ODBC. When I call the getAttachment function, I keep recieving
the error

Error Type:
ADODB.Recordset (0x800A0CC1)
Item cannot be found in the collection corresponding to the requested name or ordinal.
/MyWeb/getAttachment.asp, line 26

Any ideas as to why the record set is not returning the image? Am I closing the connection/recordset at the wrong time?

images.table
Image ID(int): att_id
Image Blob(image): ATTACHMENT

Image filename:QM1BM.TIF

<HTML>
<HEAD>Get that Attachment</HEAD>
<BODY>

<% Function GetImageData(ID)
' -- Declare Variables'
Dim objConn
Dim objRS
Dim strSQL
Dim strConnection

' -- Create objects'
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
strConnection = "DSN=DPA_Database;uid=my_Usr_ID;pwd=my_Pwd;DATABASE=DPA_Database;APP=ASP script;NETWORK=DBMSSOCN;TABLE=dbo.DPA_IMAGES"
objConn.Open strConnection

'-- Set Variables'
strSQL = "SELECT ATTACHMENT FROM dbo.DPA_IMAGES WHERE R1_ID=" & ID

on error resume next
SET objRs = objConn.Execute(strSQL)
On error goto 0

Response.write(ID)
GetImageData = objRS("ATTACHMENT")

End Function

%>


<%

' Let the browser know the file name '
'Response.AddHeader "Content-Disposition", "attachment;filename=image.tiff"'


' Let the browser know the file size '
'Response.AddHeader "Content-Length", "100000"'

'send image To the client from ASP'
Dim ID
ID = 3751

Response.ContentType = "image/tiff"
Response.BinaryWrite GetImageData(ID)

objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing

%>

</BODY>
</HTML>


This post has been edited by bananularstyle: 23 January 2007 - 08:54 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Unable to download BLOB IMAGE using ODBC

#2 bananularstyle   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-December 06

Re: Unable to download BLOB IMAGE using ODBC

Posted 23 January 2007 - 01:36 PM

After re-arranging the code, I can now load the page without errors.
Now, IE isn't prompting me to save/open.

<%
dim objConn, objRS, strSQL, strConnection
dim ID
PubID = 3751
Response.Clear
Response.Expires = -1
Response.ContentType ="image/tiff"

set objConn=server.CreateObject ("ADODB.connection")
objConn.ConnectionString="DSN=DPA_Database;uid=my_usr_id;pwd=my_pwd;DATABASE=DPA_Database;APP=ASP script;NETWORK=DBMSSOCN;TABLE=dbo.DPA_IMAGES"
source=DOUG
objConn.Open
set objRS=server.CreateObject ("ADODB.Recordset")
strSQL= "SELECT * FROM dbo.DPA_IMAGES WHERE att_id='"& ID &"'"
set objRS=objConn.Execute(strSQL)

Response.BinaryWrite objRS(4)

'Let the browser know the file name'
'Response.AddHeader "Content-Disposition", "attachment;filename=image.tiff"'
'Let the browser know the file size'
'Response.AddHeader "Content-Length", "500000"'
Response.End
objRS.Close
objConn.Close
set objConn = nothing
set objRS = nothing
%>


This post has been edited by bananularstyle: 23 January 2007 - 01:37 PM

Was This Post Helpful? 0
  • +
  • -

#3 roadfury   User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 52
  • Joined: 05-February 07

Re: Unable to download BLOB IMAGE using ODBC

Posted 05 February 2007 - 06:23 PM

Move your Response.AddHeader to a point before you write the data (and uncomment it).
Also, remove the Response.End

<%
dim objConn, objRS, strSQL, strConnection
dim ID
PubID = 3751
Response.Clear
Response.Expires = -1
Response.ContentType ="image/tiff"

set objConn=server.CreateObject ("ADODB.connection")
objConn.ConnectionString="DSN=DPA_Database;uid=my_usr_id;pwd=my_pwd;DATABASE=DPA_Database;APP=ASP script;NETWORK=DBMSSOCN;TABLE=dbo.DPA_IMAGES"
source=DOUG
objConn.Open
set objRS=server.CreateObject ("ADODB.Recordset")
strSQL= "SELECT * FROM dbo.DPA_IMAGES WHERE att_id='"& ID &"'"
set objRS=objConn.Execute(strSQL)

'Let the browser know the file name'
Response.AddHeader "Content-Disposition", "attachment;filename=image.tiff"'

Response.BinaryWrite objRS(4)

objRS.Close
objConn.Close
set objConn = nothing
set objRS = nothing
%>


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1