SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Feb 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error handling "ADODB.Stream error '800a0bba' File could not be opened"

    I am getting this error ocassionally "ADODB.Stream error '800a0bba' File could not be opened" at Function LoadStream at line objStream.LoadFromFile FilePath . Please advise me on this. When i am trying to open images.

    My Code:

    <%@ Language=VBScript %>
    <HTML>

    <%
    'Load a file from disk
    Dim FilePath
    Dim strUrl
    Dim strCheck
    dim conn
    dim rs1
    dim RecordNo
    dim equal
    dim ThreeSlashes
    dim TwoSlashes
    dim strEDMS


    strEDMS =Request.QueryString("EDMS")
    strUrl = LCase(Request.QueryString("URL"))

    strCheck = LCase("http")
    strCheckEDMS ="EDMS"
    ThreeSlashes =LCase("FILE:///\\\")
    TwoSlashes =LCase("FILE:///\\")
    strCheckslash = "\\"
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.Open "UID=cwuser;PWD=CWuS3R_C@t$w3b;DSN=catswebdatasource"
    strUrl = LCase(Request.QueryString("URL"))
    ActionID = request.QueryString("RecNo")
    ' Response.Write(strUrl)
    'Response.Write(strCheck )
    Response.Write(InStr(1, strEDMS, strCheckEDMS))
    If InStr(1, strEDMS, strCheckEDMS) >= 1 Then

    StrSQL = "select actionid,REPLACE(REPLACE(REPLACE(cast(StandardMemo006 AS varchar(255)), CHAR(10), ''), CHAR(13), ''), CHAR(9), '') as [EDMS URL] " & _
    "from Table where ACTIONID ="& ActionID
    set rs1 = conn.execute(strSQL)
    Do while not rs1.eof
    equal = rs1(1)
    rs1.movenext
    Loop
    Response.Redirect(equal)
    end if
    If InStr(1, strUrl, strCheck) >= 1 Then

    StrSQL = "select actionid,REPLACE(REPLACE(REPLACE(cast(StandardMemo006 AS varchar(255)), CHAR(10), ''), CHAR(13), ''), CHAR(9), '') as [EDMS URL] " & _
    "from Table where ACTIONID ="& ActionID
    set rs1 = conn.execute(strSQL)
    Do while not rs1.eof
    equal = rs1(1)
    rs1.movenext
    Loop

    Response.Redirect(equal)
    Else

    StrSQL = "select actionid,REPLACE(REPLACE(REPLACE(cast(StandardMemo006 AS varchar(255)), CHAR(10), ''), CHAR(13), ''), CHAR(9), '') as [EDMS URL] " & _
    "from Table where ACTIONID ="& ActionID
    set rs1 = conn.execute(strSQL)
    Do while not rs1.eof
    equal = rs1(1)
    rs1.movenext
    Loop
    equal = LCase(equal)
    If InStr(1, equal, ThreeSlashes) >= 1 Then
    equal = replace(strUrl,ThreeSlashes,"\\")
    FilePath= equal
    SendStreamToBrowser LoadStream(FilePath),FilePath,"pdf",true
    End if
    If InStr(1, equal, TwoSlashes) >= 1 Then
    equal = replace(strUrl,TwoSlashes,"\\")
    FilePath= equal
    SendStreamToBrowser LoadStream(FilePath),FilePath,"pdf",true
    End if

    'If equal = strUrl then

    equal = replace(equal,"file:///","")
    equal = replace(equal,"file://","")
    equal = replace(equal,"file:","")
    equal = replace(equal,"file:///\\","\\")

    If instr(1,equal,strCheckslash) >= 1 then
    equal= equal
    Else
    equal= strCheckslash & equal
    End if
    FilePath = equal
    SendStreamToBrowser LoadStream(FilePath),FilePath,"pdf",true


    ' Else
    ' Response.write("<h2>Access Denied</h2>")
    'Response.write(equal) + Response.write(equal)
    'End if
    End if

    Function LoadStream(FilePath)
    Dim objStream
    Set objStream = Server.CreateObject("ADODB.Stream")
    objStream.Type = 1 'adTypeBinary=1
    objStream.Open
    objStream.LoadFromFile FilePath -- error at this line

    LoadStream = objStream.Read
    objStream.Close
    Set objStream = Nothing
    End Function

    'returns the MIME header type for a given extension
    Function GetMIMEType(Extension)
    dim Ext
    Ext = UCase(Extension)
    select case Ext
    'Common documents
    case "TXT", "TEXT", "JS", "VBS", "ASP", "CGI", "PL", "NFO", "ME", "DTD"
    sMIME = "text/plain"
    case "HTM", "HTML", "HTA", "HTX", "MHT"
    sMIME = "text/html"
    case "CSV"
    sMIME = "text/comma-separated-values"
    case "JS"
    sMIME = "text/javascript"
    case "CSS"
    sMIME = "text/css"
    case "PDF"
    sMIME = "application/pdf"
    case "RTF"
    sMIME = "application/rtf"
    case "XML", "XSL", "XSLT"
    sMIME = "text/xml"
    case "WPD"
    sMIME = "application/wordperfect"
    case "WRI"
    sMIME = "application/mswrite"
    case "XLS", "XLS3", "XLS4", "XLS5", "XLW"
    sMIME = "application/msexcel"
    case "DOC"
    sMIME = "application/msword"
    case "PPT","PPS"
    sMIME = "application/mspowerpoint"

    'WAP/WML files
    case "WML"
    sMIME = "text/vnd.wap.wml"
    case "WMLS"
    sMIME = "text/vnd.wap.wmlscript"
    case "WBMP"
    sMIME = "image/vnd.wap.wbmp"
    case "WMLC"
    sMIME = "application/vnd.wap.wmlc"
    case "WMLSC"
    sMIME = "application/vnd.wap.wmlscriptc"

    'Images
    case "GIF"
    sMIME = "image/gif"
    case "JPG", "JPE", "JPEG"
    sMIME = "image/jpeg"
    case "PNG"
    sMIME = "image/png"
    case "BMP"
    sMIME = "image/bmp"
    case "TIF","TIFF"
    sMIME = "image/tiff"
    case "AI","EPS","PS"
    sMIME = "application/postscript"

    'Sound files
    case "AU","SND"
    sMIME = "audio/basic"
    case "WAV"
    sMIME = "audio/wav"
    case "RA","RM","RAM"
    sMIME = "audio/x-pn-realaudio"
    case "MID","MIDI"
    sMIME = "audio/x-midi"
    case "MP3"
    sMIME = "audio/mp3"
    case "M3U"
    sMIME = "audio/m3u"

    'Video/Multimedia files
    case "ASF"
    sMIME = "video/x-ms-asf"
    case "AVI"
    sMIME = "video/avi"
    case "MPG","MPEG"
    sMIME = "video/mpeg"
    case "QT","MOV","QTVR"
    sMIME = "video/quicktime"
    case "SWA"
    sMIME = "application/x-director"
    case "SWF"
    sMIME = "application/x-shockwave-flash"
    'Compressed/archives
    case "ZIP"
    sMIME = "application/x-zip-compressed"
    case "GZ"
    sMIME = "application/x-gzip"
    case "RAR"
    sMIME = "application/x-rar-compressed"

    'Miscellaneous
    case "COM","EXE","DLL","OCX"
    sMIME = "application/octet-stream"

    'Unknown (send as binary stream)
    case else
    sMIME = "application/octet-stream"
    end select

    GetMimeType = sMIME
    End Function

    'Sends the specified file to the browser
    sub SendStreamToBrowser(FileStream, FileName, ContentType, IsInline)
    Dim FileExt, FileSize

    'Disable error checking
    on error resume next
    'Clear buffer
    Response.Clear

    FileExt = mid(FileExt, instrrev(FileName,".") + 1)
    FileSize = Ubound(FileStream) + 1

    'Add filename to header
    Response.AddHeader "Connection", "keep-alive"
    Response.AddHeader "Content-Length", FileSize

    'Check if data should be delivered inline or not
    If IsInline = True then
    'Allow the browser to render the file inside a browser window (if it can)
    Response.AddHeader "Content-Disposition","inline; filename=" & FileName
    Else
    'Force browser to save file
    Response.AddHeader "Content-Disposition","attachment; filename=""" & FileName & """"
    End If

    'Get ContentType for download
    select case ContentType
    case false
    'Generic binary ContentType and Charset
    Response.ContentType = "application/octet-stream"
    Response.Charset = "UTF-8"

    case ""
    'Find out what it should be
    Response.ContentType = GetMIMEType(FileExt)

    case else
    'Use the ContentType that was passed
    Response.ContentType = ContentType
    end select
    'Send data to client
    Response.BinaryWrite(FileStream)
    Response.Flush
    End Sub

    %>

  2. #2
    SitePoint Addict itHighway's Avatar
    Join Date
    Jan 2008
    Location
    GUJ
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make sure the path and file name stored in variable "FileStream" is correct.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •