Text isn't the only kind of information that can be stored in databases, so of course it's not the only kind of data that ASP and ADO can handle. Binary large objects, or BLOBs, representing anything from new chemical products to graphical images, can be retrieved and stored using many of the same methods and properties used to work with text-based data.
This example accesses a database, pulls out a company logo, and sends it to the client browser. Before any database access or manipulation occurs, however, the script must tell the client browser what kind of content to expect, so the ContentType property of the Response object is set to image/GIF. This indicates that the client browser should treat the incoming information as binary data to be displayed as an image, instead of an audio file or a plain text file, for example.
CreateObject is used, just like any other database access using ADO, to create a Connection object, which is then used to open an ODBC connection with the SQL IISSDK database. A new Recordset object is instantiated and populated with the results of the SQL query execution.
The contents of the Logo field, a binary image created in the GIF format, are copied to the Pic variable, using the ActualSize property to ascertain the true length of the image, and the GetChunk method to specify how much of the image to copy. The Response.BinaryWrite method is then invoked to write the binary image to the buffer. Response.End flushes the buffer and sends the HTTP headers, including the image/GIF content-type specifier and the entire binary image, to the client browser.
Important SQL Server must be installed, and configured properly, on the same machine on which IIS is running in order for this sample to work correctly. In addition, the IISSDK data source must also be configured properly.
The VBScript and JScript versions of this script are available in the IIS samples directory, at ...\asp\database\Blob_VBScript.asp and ...\asp\database\Blob_JScript.asp.