1

I've been working on a reporting tool to summarize and link data from our Call Center system (CCS) and our bug tracking system. The tool is written in vbscript and classic ASP. One thing I have been trying to get working is retrieving attachments from the CCS. They are stored in a SQL server database as follows:

TABLE Attachment {
AttachmentID (PK, uniqueidentifier, not Null)
Filename (varchar(250))
AttachmentData (varbinary(max))
}

What I tried to do, was pass the AttachmentID guid to a simple ASP page that would retrieve the data then output it directly as a file download. When I click on the link, I get a "File Not Found" error. My code is here:

<%
  a_strConn = session("ClienteleConn")
  Set a_DBObj = Server.CreateObject("ADODB.Connection")
  a_DBObj.Open(a_strConn) 

  q_getAttachment="select FileName, AttachmentData from Attachment "_
  &"where AttachmentID='"&request("docGUID")&"'"

  set rsAttachmentData=a_DBObj.execute(q_getAttachment)

  Response.Contenttype="application/octet-stream"
  Response.AddHeader "Content-disposition","attachment;filename=" &rsAttachmentData("FileName")
  response.BinaryWrite(rsAttachmentData("AttachmentData"))
  response.end
%>

Is there a "simple" solution that still uses vbscript? Most of the samples I've found are using C# or ASP.NET.

dcoughler
  • 73
  • 1
  • 11
  • ASP.NET is not a language. It is a framework. You can use VB or C# when writing .NET code. – Diodeus - James MacFarlane Apr 10 '14 at 18:48
  • Your code seems fine. What does the file link look like? – Diodeus - James MacFarlane Apr 10 '14 at 18:52
  • You may need to enable detailed error reporting to get a better idea of the cause here. Also, how big are the attachments? `BinaryWrite` has a [4MB limit](http://support.microsoft.com/kb/944886) with buffering disabled. – Bond Apr 10 '14 at 19:45
  • Over a certain variable size you will need to use Dim q_getAttachment. – johna Apr 11 '14 at 03:16
  • The web address appearing is "../viewatt.asp?docGuid={A1E9D445-4190-4330-BD74-F14FB4539497}". The file size does not seem to be the issue since I got the same error with a 97089 byte file (a GIF). I tried to dim the query variable and the resultset variables, and that didn't seem to help. What other error reporting can I try? Any other suggestions? – dcoughler Apr 11 '14 at 13:47
  • I tried this in IE, and it directed me to the IIS server log. I found this error: |44|ASP_0106_:_80020005|Type_Mismatch 80 – dcoughler Apr 11 '14 at 14:17
  • take a look here http://stackoverflow.com/questions/6060529/read-and-write-binary-file-in-vbscript it may give you some idea. Do not want to post it as an answer since credit should go to those guys. – All Blond Apr 23 '14 at 14:33

0 Answers0