Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 28th, 2006, 02:41 PM
Registered User
 
Join Date: Aug 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default download data ("image") from SQL database problems

Hi,
I posted this in wrong forum so I'm reposting it here - hopefully someone can help?

I am using motobit to download/upload applications. I'm uploading the file as am "image" in SQL Server 2000 but when I go to download, it gives me a bunch of gibberish, like it's encoded -

My code:
<%
strConn = "Provider=SQLOLEDB; "
strConn = strConn & "Data Source=PHSSQLWEBRPD2; "
strConn = strConn & "Initial Catalog=OPRS; "
strConn = strConn & "User Id=OPRS; "
strConn = strConn & "Password=webshare"


Set Conn = Server.CreateObject("ADODB.Connection")
Conn.ConnectionString = strConn
Conn.Open
%>
<%
set RSIDB = conn.Execute("select * from DCL5.PanelUpload")
Response.ContentType ="application/octet-stream"

Response.binarywrite RSIDB("data")
%>
Any ideas? I'm fairly new to all of this, so I'm embarrassed that it may be something basic...

thank you!
-DC

 
Old August 29th, 2006, 07:27 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Is the field you are trying to display the correct field?

Also try this:

Dim byReader
byReader = Response.BinaryRead(rsidb("data"))
response.binarywrite(byReader)


Also, from your post in the SQL forum the endcoding is actually the bits of the stream converted into the corrosponding characters (nearest I can tell) and, it looks like, its a PDF file.
"The one language all programmers understand is profanity."
 
Old August 29th, 2006, 10:22 AM
Registered User
 
Join Date: Aug 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you but.. it's giving me this error:
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'Response.BinaryRead'
/idb/download.asp, line 17

(line 17 being the binaryread part of your suggested code).

It is a pdf file that I uploaded into the database. That's the admin side which functions great. The user side needs to download the pdf file, or open it at least, that's this page that's giving me trouble..

Any other ideas? Thanks so much for your time!


 
Old August 29th, 2006, 10:40 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Im sorry, it has been a very long time since i have done any hardcore ASP programming, the reason you got that error was because BinaryRead is part of the Request object, not the respone object.

However, on second thought, that should only be used when posting data from a form and then returning it to the user so lets try this instead.

Remove the lines
Dim byReader
byReader = Response.BinaryRead(rsidb("data"))

Add/Modify this:
   Response.Expires = 0
   Response.Buffer = TRUE
   Response.Clear
   Response.ContentType ="application/octet-stream"

   Response.BinaryWrite(rsidb("Data"))


hth


"The one language all programmers understand is profanity."
 
Old August 29th, 2006, 10:45 AM
Registered User
 
Join Date: Aug 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmm.. i'm getting this now.. but it opens in an asp document, not a web browser..

%PDF-1.4 %âãÏÓ 6 0 obj<> endobj xref 6 9 0000000016 00000 n 0000000609 00000 n 0000000476 00000 n 0000000685 00000 n 0000000812 00000 n 0000000896 00000 n 0000001162 00000 n 0000001352 00000 n 0000001573 00000 n trailer <<45af1f68c535c24149655e40161ad09b><9a164094c9f546 4bb13590dec7fd38d0>]>> startxref 0 %%EOF 8 0 obj<>stream xÚb```c``Ò`

 
Old August 29th, 2006, 10:55 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

ok, try this (but make sure you are pulling down a PDF file)

Response.ContentType = "application/pdf"

hth

"The one language all programmers understand is profanity."
 
Old August 29th, 2006, 10:59 AM
Registered User
 
Join Date: Aug 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

it worked!
you're genius!
I owe you a beer, or a coffee, or my firstborn! Thank you!

quick question - any idea how i could fix this so it will download any other file such as a word file? some of the will be word files as well as pdf... don't know if there's a somewhat simple way to do that?

again, thank you!!! :D

 
Old August 29th, 2006, 12:30 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Here is the thing, the application/octet-stream is kind of like the "fail safe" content type.

For example, I only use it when i am trying to push down an RTF file from my database, all other times I use the proper content type; the reason i told you to use the octet-stream is because your original post said you were pushing down applications, in which case I think .exe files, and you should use the octet-stream.

What you have to do is either:
A) Depending on how your uploading component works, you may be able to get the content type of the file your uploading by doing something similar to this: file.ContentType, if you can capture that place that value in your database and then set your content type dynamically as you pull down your file.
     e.g. Response.ContentType = rsidb("contenttype")

B) Setup a case statement on the upload side to capture the file extension and, based on extension, place that into the database. (.doc files get application/vnd.ms-word, pdf gets application/pdf, etc)

In .NET I am able to capture the ContentType of any file sent through an HtmlInputFile control and save that directly to my database so there is no guess work, since you are using Classic asp, i think you may be limited to what your particular Component can do.

(in any case you should be able to loop through the component and check for the contenttype, check your documentation from motobit)

Ill take a Corona with a Lemon, thank you very much!

hth.

"The one language all programmers understand is profanity."
 
Old August 29th, 2006, 01:04 PM
Registered User
 
Join Date: Aug 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

wow... okay, see this is what learning ASP on my own gets me.. lots of holes in my learning, but you have given me a lot to look up and learn so I'll be doing that!

thanks again for all of your help.. i tried squeezing in the corona but it almost fried my keyboard ;)

 
Old August 29th, 2006, 01:10 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Here is a listing of most of the common content types:

http://www.topxml.com/asp/response_o...ontenttype.asp

"The one language all programmers understand is profanity."





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems in Image Data Type ayan.mukherjee VB Databases Basics 0 June 30th, 2008 03:54 AM
Download in Image from Sql Server 2000 using asp surendraparashar Classic ASP Basics 0 December 16th, 2007 11:55 PM
download data ("image") from SQL database problems alex9183 Classic ASP Databases 2 September 14th, 2006 09:02 AM
Problems Displaying an image retrieved from SQL Se jazzcatone ASP.NET 1.x and 2.0 Application Design 2 September 3rd, 2005 09:53 AM
IS There A Way TO Download Data F Sql To Xml File alyeng2000 ASP.NET 1.0 and 1.1 Professional 4 April 28th, 2005 09:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.