ADODB.Stream crashes IE

Posted on 2005-04-29
Last Modified: 2011-08-18

On our website we've got a flash player that streams MP3's, the flash player is fed using an ASP script that streams the MP3 as binary data. Using Internet Explorer, and after listening to a few songs, the browser first of all becomes sluggish and then crashes. This only happens when the songs is not allowed to finish, normally when the song finishes, the flash player clears the memory of any data that has been sent to it...The player appears in a pop-up window, if the user clicks on the normal 'X' button to close the window, the flash player cannot clear the memory. I am trying to figure out whether the script i am using to stream the data will continue executing even if the calling object, i.e. the flash player, has been closed.

Within my code, can anyone see any problems in the code, or the potential for the script to continue executing even when the calling object is no longer making calls to it??

Response.Expires = 0
Response.Expiresabsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"

'declare file variables
Dim strPath, strFile, strExt
Dim bolIsError, strError
Dim objMail
Dim bolIsFlashCall

'assign values to variables
strPath = Server.MapPath("/mp3/")
strFile = Request.QueryString("qryFile")
strExt = LCase(Right(strFile,Len(strFile)-inStr(strFile,".")+1))
bolIsFlashCall = Request.Form("encryption")

'//Name: GetFile()
'//Purpose: To return the file object to playlist.asp
Public Sub GetFile(strFile)

      'check a valid filename was provided
      If (strFile = "" Or strExt = "") Or (strExt <> "" And strExt = ".wma") Then
            bolIsError = True
      End If
      'only continue if a file has been provided
      If bolIsError = False Then

            'declare variables
            Dim sFile
            Dim objStream
            Dim lBlockSize
            Dim lFileSize
            Dim lCount
            'create an instance of the filesystem object
            Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
            'only continue if the file exists
            If objFso.FileExists(strPath & "\" & strFile) Then
                  'get a handle on the file
                  Set sFile = objFSO.GetFile(strPath & "\" & strFile)
                  'get the size of the file in bytes
                  lFileSize = sFile.Size
                  'create an instance of the stream object
                  Set objStream = Server.CreateObject("ADODB.Stream")
                  'open the stream
                  ' Set the Stream to Binary (not Text)
                  objStream.Type = 1
                  'load the content of the MP3/Video into the stream object
                  objStream.LoadFromFile(strPath & "\" & strFile)
                  'change the HTTP header to reflect that a binary file is being passed.
                  Response.Expires = 0
                  Response.Buffer  = True
                  'set the correct content type depending on the media type
                  Select Case strExt
                        Case ".mp3"
                              Response.ContentType = "audio/octet-stream"
                        Case ".flv"
                              Response.ContentType = "video/octet-stream"
                  End Select
                  randomize timer
                  Response.AddHeader "Content-Disposition", "inline;filename=temp" & int(rnd()*9999999999) & strExt
                  Response.AddHeader "Content-Length", lFileSize
                  Response.CharSet = "UTF-8"
                  ' While...Wend to send bulk of file
                  While lFileSize > lBlockSize + lCount And Response.IsClientConnected = True
                               lCount = lCount + lBlockSize
                               Response.BinaryWrite objStream.Read(lBlockSize)
                              ' Make sure each Block is sent before sending the next one

                  ' Main bulk of file now sent - Just the last bit to go...
                  Response.BinaryWrite objStream.Read(lFileSize - lCount)
                  ' Don't forget to flush that last little bit
                  'close all objects
                  Set objFso = Nothing
                  Set objStream = Nothing
                  Set sFile = Nothing
                  'do not execute any further
            End If 'end if file exists

End Sub

Call GetFile(strFile)

Any help would be greatly appreciated.....

Thanks in advance

Question by:higgsy
    LVL 11

    Expert Comment


    Try adding the line inside the do while loop to check whether the client is on session

    if Response.IsClientConnected = false then Response.End

    LVL 15

    Accepted Solution

    > I am trying to figure out whether the script i am using to stream the data will continue
    > executing even if the calling object, i.e. the flash player, has been closed.

    I understand your question then it seems to me that this isn't the problem.

    The problem is with the client. If the flash app has been closed then your script may still be executing but there's no client application to receive the output - so it can't the cause the of the browser crash.

    So my guess is the the flash app is NOT closing down properly or it's not sending the an HTTP disconnect header when it's closed.

    At this stage I would be looking closely at the flash app before assuming it's a problem with the server-side code.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
    Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now