Downloading Files stored in SQL Server

F

fibreiv

I am trying to download files from my database that I uploaded to it. I can
download bmp, txt file but have not been able to d/l pdf files. I am able to
d/l pdf files stored in the file system but not in the database. Any help
would be great. Here is my code, I have hard coded the file to download for
testing purposes.

Connect = "Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;Password=;Initial Catalog=INNB;Data Source=pompom"

Set db = Server.CreateObject("ADODB.Connection")
db.Open Connect

SQL = "SELECT filesize, contenttype, filename, filedata FROM thefiles where
id = 2"
Set rs = db.Execute( SQL )
If rs.EOF Then Response.End
Response.ContentType = "application/pdf"
Response.AddHeader "Content-Disposition", "attachment;filename=agencies.pdf"
Response.AddHeader "Content-Length", "16863"
Response.BinaryWrite rs("filedata")



Thanks,
Brett Bishop
MCSE, MCP+I
US Bankruptcy Court
 
L

larrybud2002

fibreiv said:
I am trying to download files from my database that I uploaded to it. I can
download bmp, txt file but have not been able to d/l pdf files. I am able to
d/l pdf files stored in the file system but not in the database. Any help
would be great. Here is my code, I have hard coded the file to download for
testing purposes.

Connect = "Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;Password=;Initial Catalog=INNB;Data Source=pompom"

Set db = Server.CreateObject("ADODB.Connection")
db.Open Connect

SQL = "SELECT filesize, contenttype, filename, filedata FROM thefiles where
id = 2"
Set rs = db.Execute( SQL )
If rs.EOF Then Response.End
Response.ContentType = "application/pdf"
Response.AddHeader "Content-Disposition", "attachment;filename=agencies.pdf"
Response.AddHeader "Content-Length", "16863"
Response.BinaryWrite rs("filedata")

So what kind of error do you get? How do you know the length is
16863??

When I do my binary retrieves I don't specify the length.

Here's my generic getbinary.asp page... When a file is uploaded I store
the mime type of the file.

<!-- #INCLUDE VIRTUAL="/adovbs.inc" -->

<%
ID = Request.QueryString("ID")
tablename=Request.QueryString("tablename")
idfieldname=Request.QueryString("idfieldname")
datafield=Request.QueryString("datafield")
datacon=session("DB_CONNECTIONSTRING")
Set con2 = Server.CreateObject("ADODB.Connection")
Con2.open(datacon)

mysql2="select * from " & tablename &" where "& idfieldname & "=" & ID
Set rs2=con2.execute(mysql2)

if not rs2.EOF then
Response.ContentType = rs2("type_"&right(datafield,
len(datafield)-4))
Response.BinaryWrite(rs2(datafield))
else
Response.Write("Record '" + ID + "' not found.")
end if

rs2.Close
%>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta name="Microsoft Theme" content="none, default">
</head>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top