473,626 Members | 3,965 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adodb.Stream - Problem download big files

Hi!
I want to use ASP to download big files using ADODB.STREAM. It works very
fine with files smaller than 80 MB.
On the Webserver I can see that memory allocation and the process w3wp is
running. After some time (more or less 2 minutes) I get a response timeout.

Here is the code:

Server.ScriptTi meout = 30000
Response.Buffer = True

Response.Clear
Response.Expire s = 0
Response.Conten tType = "Download-File"
Response.AddHea der "Content-Disposition","a ttachment; filename=" & sfile

Set oStream = Server.CreateOb ject("ADODB.Str eam")
oStream.Type = adTypeBinary
oStream.Open
oStream.LoadFro mFile(sfile)
Response.AddHea der "Content-Length", oStream.Size ' -- Schönheit
Response.CharSe t = "UTF-8"

For i = 0 To oStream.Size
i = i + 128000
Response.Binary Write(oStream.R ead(128000))
Response.Flush

Next

oStream.Close
Set oStream = Nothing
Response.Flush
Response.End

Do I have to change something in my code - or perhaps a general setting in
IIS / the metabase?

Many thanks in advance

Juan
Jul 3 '08 #1
10 19326
"Juan" <Ju**@discussio ns.microsoft.co mwrote in message
news:71******** *************** ***********@mic rosoft.com...
Hi!
I want to use ASP to download big files using ADODB.STREAM. It works very
fine with files smaller than 80 MB.
On the Webserver I can see that memory allocation and the process w3wp is
running. After some time (more or less 2 minutes) I get a response
timeout.
>
Here is the code:

Server.ScriptTi meout = 30000
30,000 seconds is a long script time out ;)
Response.Buffer = True
Change to False, you don't want to buffer anyway (yes I know you are
flushing but this is simpler).
>
Response.Clear
Response.Expire s = 0
Response.Conten tType = "Download-File"
This is not a valid content type if you don't know what the content type is
use the fallback type: "applicatio n/octet-stream"
Response.AddHea der "Content-Disposition","a ttachment; filename=" & sfile

Set oStream = Server.CreateOb ject("ADODB.Str eam")
oStream.Type = adTypeBinary
oStream.Open
oStream.LoadFro mFile(sfile)
Response.AddHea der "Content-Length", oStream.Size ' -- Schönheit
Don't add the Content-Length header its a duplication, ASP adds that for
you.
Response.CharSe t = "UTF-8"
How come you know the character encoding but don't know the content type?
Consider deleting this line or setting the content-type to the correct text
type.

>
For i = 0 To oStream.Size
i = i + 128000
Response.Binary Write(oStream.R ead(128000))
Response.Flush
No need for a flush when buffering is off.
>
Next

oStream.Close
Set oStream = Nothing
Response.Flush
Response.End
Again no need for a flush and .End is draconian, only use it if you know
something bad will happen if you don't. Even then design out the something
bad rather than use .End.
>
Do I have to change something in my code - or perhaps a general setting in
IIS / the metabase?
The response timeout is a clientside thing however normally response
timeouts related to the time it takes to get the first chunk of data not the
overall send time.

--
Anthony Jones - MVP ASP/ASP.NET
Jul 3 '08 #2
Anthony wrote on Thu, 3 Jul 2008 14:33:27 +0100:
"Juan" <Ju**@discussio ns.microsoft.co mwrote in message
news:71******** *************** ***********@mic rosoft.com...
>Hi!
>I want to use ASP to download big files using ADODB.STREAM. It works
very fine with files smaller than 80 MB.
On the Webserver I can see that memory allocation and the process
w3wp is running. After some time (more or less 2 minutes) I get a
response
timeout.
>Set oStream = Server.CreateOb ject("ADODB.Str eam")
oStream.Type = adTypeBinary oStream.Open oStream.LoadFro mFile(sfile)
Response.AddHe ader "Content-Length", oStream.Size ' -- Schönheit
Don't add the Content-Length header its a duplication, ASP adds that
for you.
If the stream is being written out in chunks (which it is in the For Next
loop), how does the ASP engine know what the final size will be?

--
Dan
Jul 3 '08 #3
Juan wrote on Thu, 3 Jul 2008 06:00:01 -0700:
Hi!
I want to use ASP to download big files using ADODB.STREAM. It works
very fine with files smaller than 80 MB.
On the Webserver I can see that memory allocation and the process w3wp
is running. After some time (more or less 2 minutes) I get a response
timeout.
Here is the code:
Server.ScriptTi meout = 30000
Response.Buffer = True
Response.Clear
Response.Expire s = 0
Response.Conten tType = "Download-File"
Response.AddHea der "Content-Disposition","a ttachment; filename=" &
sfile
Set oStream = Server.CreateOb ject("ADODB.Str eam")
oStream.Type = adTypeBinary oStream.Open oStream.LoadFro mFile(sfile)
Response.AddHea der "Content-Length", oStream.Size ' -- Schönheit
Response.CharSe t = "UTF-8"
For i = 0 To oStream.Size
i = i + 128000
Response.Binary Write(oStream.R ead(128000))
Response.Flush
Next
This looks odd - you're looping from 0 to the size of the stream, yet you're
pushing out 128000 bytes at a time. I think you should be using

For i = 0 To oStream.Size Step 128000
Also, in your loop what happens when you reach the end of the stream?
This is how I handle download from one of my applications

Set oStream = Server.CreateOb ject("ADODB.Str eam")
Call oStream.Open()
oStream.Type = 1
call oStream.LoadFro mFile(strFilena me)

iDownload = 1
If lcase(right(str filename,4)) = ".pdf" then
Response.Conten tType = "applicatio n/pdf"
else
Response.Conten tType = "applicatio n/octet-stream"
end if
Response.AddHea der "Content-Disposition", "filename=" &
strfilename & ";"

Response.Buffer = False

'stream out the file in chunks
Do While Not (oStream.EOS)
Response.Binary Write oStream.Read(10 24 * 256)
Loop

oStream.Close
Set oStream = Nothing
this reads the file into the stream (just like you already have), sets an
appropriate ContentType (as Anthony points out the one you use is not a
recognised MIME type), turns off buffering, and then writes out the stream
in 256kB chunks until there is nothing left to write to out (using
oStream.EOS to determine if the stream is at the end).

You really do need buffering turned off - it's entirely possible that the
80MB file is going over the defined ASP buffer limit and so you're getting
an ASP error thrown into the data, and that causes what appears to be a
timeout but is actually due to ASP terminating the script because it has
errored. So far with the above code I've had no trouble with files larger
than the defined ASP buffer limit, but I haven't tried it with anything as
large as your file.

--
Dan
Jul 3 '08 #4
Daniel wrote to Anthony Jones on Thu, 3 Jul 2008 17:14:31 +0100:
Anthony wrote on Thu, 3 Jul 2008 14:33:27 +0100:
>"Juan" <Ju**@discussio ns.microsoft.co mwrote in message
news:71******* *************** ************@mi crosoft.com...
>>Hi!
>>I want to use ASP to download big files using ADODB.STREAM. It works
very fine with files smaller than 80 MB.
On the Webserver I can see that memory allocation and the process
w3wp is running. After some time (more or less 2 minutes) I get a
response
timeout.
>>Set oStream = Server.CreateOb ject("ADODB.Str eam")
oStream.Typ e = adTypeBinary oStream.Open oStream.LoadFro mFile(sfile)
Response.AddH eader "Content-Length", oStream.Size ' -- Schönheit
>Don't add the Content-Length header its a duplication, ASP adds that
for you.
If the stream is being written out in chunks (which it is in the For
Next loop), how does the ASP engine know what the final size will be?
Actually, I've just realised that the code I use myself doesn't set the
Content-Length header either. ASP doesn't add the Content-Length header
itself either as it has no idea what the file size is when it starts
outputting it, here's an example of the ASP headers from a download from my application:

HTTP/1.1 200 OK
Cache-Control: private
Date: Thu, 03 Jul 2008 16:26:53 GMT
Transfer-Encoding: chunked
Content-Type: application/pdf
Server: Microsoft-IIS/6.0
Content-Disposition: filename=Certif ications_at_a_G lance.pdf;
This just means that you don't get the status bar in IE, for instance,
showing the download progress because the final size is not known. Adding
the Content-Length header allows IE (and any other browser that will show a
status bar) to give a progress with a final size value. I tested adding the
content length header to my own application and the headers changed to:

HTTP/1.1 200 OK
Cache-Control: private
Date: Thu, 03 Jul 2008 16:29:46 GMT
Transfer-Encoding: chunked
Content-Length: 1890660
Content-Type: application/pdf
Server: Microsoft-IIS/6.0
Content-Disposition: filename=Certif ications_at_a_G lance.pdf;

and appeared to have no detrimental effect on the download.

--
Dan
Jul 3 '08 #5
Daniel wrote to Juan on Thu, 3 Jul 2008 17:22:58 +0100:
Juan wrote on Thu, 3 Jul 2008 06:00:01 -0700:
>Hi!
>I want to use ASP to download big files using ADODB.STREAM. It works
very fine with files smaller than 80 MB.
On the Webserver I can see that memory allocation and the process
w3wp is running. After some time (more or less 2 minutes) I get a
response timeout.
>Here is the code:
>Server.ScriptT imeout = 30000
Response.Buffe r = True
>Response.Cle ar
Response.Expir es = 0
Response.Conte ntType = "Download-File"
Response.AddHe ader "Content-Disposition","a ttachment; filename=" &
sfile
>Set oStream = Server.CreateOb ject("ADODB.Str eam")
oStream.Type = adTypeBinary oStream.Open
oStream.LoadFr omFile(sfile)
Response.AddHe ader "Content-Length", oStream.Size ' -- Schönheit
Response.CharS et = "UTF-8"
>For i = 0 To oStream.Size i = i + 128000
Response.Binary Write(oStream.R ead(128000))
Response.Flush
Next
This looks odd - you're looping from 0 to the size of the stream, yet
you're pushing out 128000 bytes at a time. I think you should be using
I actually had another idea as to why it might be "timing out" - for 80MB of
data, your loop is running 83886080 times (80 * 1024 * 1024). If you are
using 128kB chunks, it only needs 666 loops to send 80MB. Check your event
logs and see if you have any ASP or IIS events pointing to the process being
terminated.

--
Dan
Jul 3 '08 #6
"Daniel Crichton" <ms****@worldof spack.comwrote in message
news:ey******** ******@TK2MSFTN GP06.phx.gbl...
Daniel wrote to Juan on Thu, 3 Jul 2008 17:22:58 +0100:
Juan wrote on Thu, 3 Jul 2008 06:00:01 -0700:
>Hi!

>I want to use ASP to download big files using ADODB.STREAM. It works
>very fine with files smaller than 80 MB.
>On the Webserver I can see that memory allocation and the process
>w3wp is running. After some time (more or less 2 minutes) I get a
>response timeout.
>Here is the code:
>Server.ScriptT imeout = 30000
>Response.Buffe r = True
>Response.Cle ar
>Response.Expir es = 0
>Response.Conte ntType = "Download-File"
>Response.AddHe ader "Content-Disposition","a ttachment; filename=" &
>sfile
>Set oStream = Server.CreateOb ject("ADODB.Str eam")
>oStream.Type = adTypeBinary oStream.Open
>oStream.LoadFr omFile(sfile)
>Response.AddHe ader "Content-Length", oStream.Size ' -- Schönheit
>Response.CharS et = "UTF-8"
>For i = 0 To oStream.Size i = i + 128000
> Response.Binary Write(oStream.R ead(128000))
> Response.Flush
>Next
This looks odd - you're looping from 0 to the size of the stream, yet
you're pushing out 128000 bytes at a time. I think you should be using

I actually had another idea as to why it might be "timing out" - for 80MB
of
data, your loop is running 83886080 times (80 * 1024 * 1024). If you are
using 128kB chunks, it only needs 666 loops to send 80MB. Check your event
logs and see if you have any ASP or IIS events pointing to the process
being
terminated.
The loop is incrementing 128001 every iteration so potentially it may not
send all the file

--
Anthony Jones - MVP ASP/ASP.NET
Jul 3 '08 #7
"Daniel Crichton" <ms****@worldof spack.comwrote in message
news:eJ******** ******@TK2MSFTN GP06.phx.gbl...
Daniel wrote to Anthony Jones on Thu, 3 Jul 2008 17:14:31 +0100:
Anthony wrote on Thu, 3 Jul 2008 14:33:27 +0100:
>"Juan" <Ju**@discussio ns.microsoft.co mwrote in message
>news:71******* *************** ************@mi crosoft.com...
>>Hi!

>>I want to use ASP to download big files using ADODB.STREAM. It works
>>very fine with files smaller than 80 MB.
>>On the Webserver I can see that memory allocation and the process
>>w3wp is running. After some time (more or less 2 minutes) I get a
>>response
>timeout.

>>Set oStream = Server.CreateOb ject("ADODB.Str eam")
>>oStream.Typ e = adTypeBinary oStream.Open oStream.LoadFro mFile(sfile)
>>Response.AddH eader "Content-Length", oStream.Size ' -- Schönheit
>Don't add the Content-Length header its a duplication, ASP adds that
>for you.
If the stream is being written out in chunks (which it is in the For
Next loop), how does the ASP engine know what the final size will be?

Actually, I've just realised that the code I use myself doesn't set the
Content-Length header either. ASP doesn't add the Content-Length header
itself either as it has no idea what the file size is when it starts
outputting it, here's an example of the ASP headers from a download from
my application:
>
HTTP/1.1 200 OK
Cache-Control: private
Date: Thu, 03 Jul 2008 16:26:53 GMT
Transfer-Encoding: chunked
Content-Type: application/pdf
Server: Microsoft-IIS/6.0
Content-Disposition: filename=Certif ications_at_a_G lance.pdf;
This just means that you don't get the status bar in IE, for instance,
showing the download progress because the final size is not known. Adding
the Content-Length header allows IE (and any other browser that will show
a
status bar) to give a progress with a final size value. I tested adding
the
content length header to my own application and the headers changed to:

HTTP/1.1 200 OK
Cache-Control: private
Date: Thu, 03 Jul 2008 16:29:46 GMT
Transfer-Encoding: chunked
Content-Length: 1890660
Content-Type: application/pdf
Server: Microsoft-IIS/6.0
Content-Disposition: filename=Certif ications_at_a_G lance.pdf;

and appeared to have no detrimental effect on the download.
You're right it doesn't have any detrimental affect on IE in fact it serves
a useful purpose. However it is a strictly a breach of the protocol See
http://www.w3.org/Protocols/rfc2616/...c4.html#sec4.4 para 3.
However the protocol does then indicate that if it is Content-Length is
present it should be ignored in this case.
--
Anthony Jones - MVP ASP/ASP.NET
Jul 3 '08 #8
"Juan" <Ju**@discussio ns.microsoft.co mwrote in message
news:71******** *************** ***********@mic rosoft.com...
Hi!
I want to use ASP to download big files using ADODB.STREAM. It works very
fine with files smaller than 80 MB.
On the Webserver I can see that memory allocation and the process w3wp is
running. After some time (more or less 2 minutes) I get a response
timeout.
>
Here is the code:

Server.ScriptTi meout = 30000
Response.Buffer = True

Response.Clear
Response.Expire s = 0
Response.Conten tType = "Download-File"
Response.AddHea der "Content-Disposition","a ttachment; filename=" & sfile

Set oStream = Server.CreateOb ject("ADODB.Str eam")
oStream.Type = adTypeBinary
oStream.Open
oStream.LoadFro mFile(sfile)
Response.AddHea der "Content-Length", oStream.Size ' -- Schönheit
Response.CharSe t = "UTF-8"

For i = 0 To oStream.Size
i = i + 128000
Response.Binary Write(oStream.R ead(128000))
Response.Flush

Next

oStream.Close
Set oStream = Nothing
Response.Flush
Response.End

Do I have to change something in my code - or perhaps a general setting in
IIS / the metabase?

Many thanks in advance

FYI this is the routine I use for sending a file to response.

Sub SendFileToRespo nse(FilePath, FileName)

Const clChunkSize = 1048576 ' 1MB

Dim oStream, i
Response.Buffer = False

Response.Conten tType = "applicatio n/octet-stream"
Response.AddHea der "Content-Disposition", _
"attachment ; Filename=" & FileName

Set oStream = Server.CreateOb ject("ADODB.Str eam")
oStream.Type = 1 ' Binary
oStream.Open
oStream.LoadFro mFile FilePath

For i = 1 To oStream.Size \ clChunkSize
Response.Binary Write oStream.Read(cl ChunkSize)
Next
If (oStream.Size Mod clChunkSize) <0 Then
Response.Binary Write oStream.Read(oS tream.Size Mod clChunkSize)
End If
oStream.Close

End Sub

1MB buffer is a bit on the big side though 128K is a good choice.

--
Anthony Jones - MVP ASP/ASP.NET
Jul 3 '08 #9
Anthony Jones wrote on 03 jul 2008 in
microsoft.publi c.inetserver.as p.general:
FYI this is the routine I use for sending a file to response.

Sub SendFileToRespo nse(FilePath, FileName)

Const clChunkSize = 1048576 ' 1MB

Dim oStream, i
Response.Buffer = False

Response.Conten tType = "applicatio n/octet-stream"
Response.AddHea der "Content-Disposition", _
"attachment ; Filename=" & FileName

Set oStream = Server.CreateOb ject("ADODB.Str eam")
oStream.Type = 1 ' Binary
oStream.Open
oStream.LoadFro mFile FilePath

For i = 1 To oStream.Size \ clChunkSize
Response.Binary Write oStream.Read(cl ChunkSize)
Next
If (oStream.Size Mod clChunkSize) <0 Then
Response.Binary Write oStream.Read(oS tream.Size Mod clChunkSize)
End If
Would an error be given if an empty chunk or is sent?
And if the requested chunk size is larger than the remainder?

If not I would do:

For i = 0 To oStream.Size \ clChunkSize
Response.Binary Write oStream.Read(cl ChunkSize)
Next
oStream.Close

End Sub

1MB buffer is a bit on the big side though 128K is a good choice.


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 4 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
13049
by: Robert Brown | last post by:
Hi All, I am creating an interface into a Payment Gateway. I need to access a URL (which is a perl script) with paramters attached. I will then get a response within 10 seconds with information I need to formulate into my pretty asp page. I didn't know where to start but I have read alot about adodb.stream. I setout to write some code and this is what I have done:
2
690
by: Richard K Bethell | last post by:
Hi, We have an application, written in ASP, that uses the ADODB.Stream to be able to open files and write byte arrays to the Response object. If one of our administrators patches the web servers this application runs on in Windows Update, I'm screwed, right? You've essentially just disabled this COM object, for not only its evil purposes, but its useful ones? Richard
0
2104
by: microsoft | last post by:
Hi, I have an ASP script that initiates a ADODB.Stream like below first bit gets filename from the database strAbsFile = getfilefromDB(request.querystring("fileid")) '-- create FSO object to check if file exists and get properties Set objFSO = Server.CreateObject("Scripting.FileSystemObject") '-- check to see if the file exists
1
1829
by: A | last post by:
Hi all, I have an ASP page that downloads file with the ADODB.Stream object. I've found that if the user click cancel in the "Save file as" window or during the downloading, the download is no more available, the page hangs over and and the session have to be closed. (In some cases you have to Cancel more than one time the download process to rise up this error). I've experienced this problem, as a user, with many major webmail...
1
5242
by: guyv | last post by:
Hello! I wanna read binary data from database with ADODB.Stream object. So I wrote code.. --------- <% query = "SELECT * FROM Categories" adoDB.DefaultDatabase = "Northwind"
3
9475
by: C | last post by:
Re: Microsoft Knowledge Base Article - 870669 How to disable the ADODB.Stream object from Internet Explorer You may recently have heard of the vulnarability exposed by Internet Explorer as described in that article: "An ADO stream object contains methods for reading and writing binary files and text files. When an ADO stream object is combined with known security vulnerabilities in Internet Explorer, a Web site could execute scripts...
4
9952
by: Fresh_Air_Rider | last post by:
Hi In the "good old" Classic ASP days, I used to stream records from a SQL Server database out to the user's browser in CSV format by using a combination of COALESCE and the ADODB.Stream object. The trouble is that I'm not really sure how to do this in C# 2005. This was a very useful technique and if anyone could please show me how to adapt the Classic ASP code to C# 2005, I'd be very grateful indeed.
7
9879
by: iporter | last post by:
I use the code below to authorise the download of certain files. Thus, instead of linking to the file in a wwwroot directory, I link to this code with the filename as a parameter, and the script streams the file if the user is authorised. This has worked fine on PDFs, DOCs, XLS, etc. until today, and 18MB file presents the error message 'format error: not a pdf or corrupt'. Is there a file size limit, or a default that needs...
3
9220
gauravgmbhr
by: gauravgmbhr | last post by:
Hi All, I am trying to open a binary stream from a file and the creating a new stream from the opened stream and then trying to over wright the file and i am getting the following error ADODB.Stream error '800a0bbc' Write to file failed. /cops/RestartV1.asp, line 80
0
8266
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8705
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8365
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7196
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5574
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4092
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2626
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.