Question : Binary Object Stream (PDF)

We have the following code that reads a binary object from a MSSQL database and renders to the user.  It works on most computers in both FireFox and Internet Explorer.  However, it does not work on the system of the user that this was designed for.  On this system, ascii characters are displayed on the screen.  Other websites with links to PDFs work fine on her system.

Here is the code we're using:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
Response.ContentType = "application/pdf"
	
	'Variable declaration
	Dim objStream
	Dim fileRS, fileSQL
	Const adTypeBinary = 1
	
	fileSQL = "SELECT fileName, fileData FROM tblAuditDocs WHERE tblAuditDocs.auditDocID = " + fileID
	Set fileRS = Server.CreateObject("ADODB.Recordset")
	fileRS.Open fileSQL,oConn,1,1,1
	
	If Not(fileRS.EOF) Then
		Response.ContentType = "application/pdf"
		
		Set objStream = Server.CreateObject("ADODB.Stream") 
		objStream.Open 
		objStream.Type = adTypeBinary
		objStream.Write fileRS("fileData").value
		
		'IMPORTANT:  Must set position at the beginning of the stream
		objStream.Position = 0
		
		Response.BinaryWrite objStream.Read
		'Response.End
		Set objStream = Nothing
	End If
	
	fileRS.Close
	Set fileRS = Nothing


Here is the start of the output to the screen:
%PDF-1.5 %âãÏÓ 1 0 obj<> endobj 2 0 obj<> endobj 3 0 obj<> endobj 4 0 obj<> endobj 5 0 obj<</XOBJECT<< 0 R 6 I0>>/ProcSet[/PDF/ImageB/Text]>> endobj 6 0 obj<<< CCITTFaxDecode] Filter[ 258524>>]/Width 2560/Height 3256/BitsPerComponent 1/ColorSpace/DeviceGray/Type/XObject/Subtype/Image>>stream ÿÿÿÿÿÿå” GÿÿÿÿÿÿÿÿÿÿÿÿÿþW   ê¢m FÚEÑ  Eñ•Î‹ DDŒ È+ðrpAg p‚K  $ Ê 1)Ô":  í‘Ѭ™,"8©  Ä\a èRH M…a,  P„6 Ç(p@…¥  A `¢Ä9’š Ž!  Ø”9C„ÈϤ  † ¡8á Pi$Ð">ì  º#¤U‘@YI  #èà FÂ# Š '
 xE9‡ ÕŠ6˜°‚Š Z(p‚dv  )Í` % A
 ‚#¤ ŽM¢‡eÐ! )÷ 6!„ •2,@¢;t Q(p@’H*A‘à‚ a ‡Ä#h"œ¡Ø4Š  œFÊ ">Ä !r‡  Á ˆätGP à‚l` ±ôS„ M9t §(r‡    Dt ¡Á Œº¡ A ÒDu   I$ ô‚@ ! çò:  „l(Ž Ð$’A a úH$‡ 0å
)#  Tš,p QC”8":  Çé(H$˵ ØH $Œ8 B! "ûE
 M$ „ ˆD~! ù ¡¤ W  „‚# E
 ¼Á ,-œHã”8A4   ¤Ò* *(qXI+ ‚)Á V˜@‚ #

Answer : Binary Object Stream (PDF)

oh my friend, you're using text datatype. That's not good. are you using SQL 2005? If so, then I urge you to change it to varchar(max) in order to avoid yourself lots of trouble in the future. If you're using SQL 2000, then definitively consider varchar(8000). In the mean time, we can try with "like" operator instead

1:
2:
3:
select a.* 
from payment a
inner join notesTEST b on a.id = b.CUSTOMER_id and dateadd(d, datediff(d, 0, a.[date]), 0) >= dateadd(d, datediff(d, 0, b.[date]), 0) and b.notes like '%' + cast(abs(A.value) as varchar) + '%'
Random Solutions  
 
programming4us programming4us