title: export SQL Server binary data via a URL with VBScript and classic ASP
body: <p>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:</p>
  
  <pre><code>TABLE Attachment {
  AttachmentID (PK, uniqueidentifier, not Null)
  Filename (varchar(250))
  AttachmentData (varbinary(max))
  }
  </code></pre>
  
  <p>What I <em>tried</em> 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:</p>
  
  <pre><code>&lt;%
    a_strConn = session("ClienteleConn")
    Set a_DBObj = Server.CreateObject("ADODB.Connection")
    a_DBObj.Open(a_strConn) 
  
    q_getAttachment="select FileName, AttachmentData from Attachment "_
    &amp;"where AttachmentID='"&amp;request("docGUID")&amp;"'"
  
    set rsAttachmentData=a_DBObj.execute(q_getAttachment)
  
    Response.Contenttype="application/octet-stream"
    Response.AddHeader "Content-disposition","attachment;filename=" &amp;rsAttachmentData("FileName")
    response.BinaryWrite(rsAttachmentData("AttachmentData"))
    response.end
  %&gt;
  </code></pre>
  
  <p>Is there a "simple" solution that still uses vbscript? Most of the samples I've found are using C# or ASP.NET.</p>