SOLVED - Problem retrieving a PDF file stored in SQL Server in an ASP.NET application

cyberia

Platinum Member
Oct 22, 1999
2,535
0
0
I have been scratching my head trying to fiigure out what is going on here. Any help would be appreciated.

I have an ASP.NET application, written in VS 2008 and running on Server 2008, that allows a user to upload PDF files which are then displayed in a list and can be viewed/downloaded. The files are stored in a SQL table as a binary field.

Problem: Two recently uploaded PDF files cannot be retrieved for viewing or download. I get the following error in Acrobat Reader: "There was an error opening this document. The file is damaged and could not be repaired".

Here is the strange part:
  • Previously uploaded files work fine
  • An identical copy of the web application running on a Windows Server 2003 box does NOT have this problem

I am leaning toward blaming a weird sequence of bytes in the PDF file that may be triggering a security violation on IIS7/Server 2008 that causes it to interrupt the response. But I can't exactly pinpoint it.
 
Last edited:

WannaFly

Platinum Member
Jan 14, 2003
2,811
1
0
1) Did you recently move it to Server 2008, and if you upload a new file does it work? Are you sure it's not the upload process that is faulty? Well, I guess the identical copy rules this out, but its worth a guess.

2) Can you verify the file size? IIS really wouldnt randomly change bytes around. Maybe its sending a 0kb File? Or you are hitting the max response limit, and it's cutting the response off early (if its a very large PDF)

3) Is the identical copy using the same datasource?
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
If you use a packet sniffer like WireShark or an in-browser tool like IEWatch or Fiddler you can look at the server response headers, including the content type, content length, and response body.
 

cyberia

Platinum Member
Oct 22, 1999
2,535
0
0
1) No, it has been on this 2008 box for a while. The upload process and the data stored in the SQL Server must be OK because the retrieval works on the 2003 box.

2) The file is under 18KB. The retrieval gets cut off somewhere around 16,700 Bytes. (The upload uploads the entire 18KB since the entire file can be retrieved on the 2003 mashine). I experimented with dummy PDF files of various sizes, both smaller and larger: They all get uploaded and are later retrieved properly.

3) Yes, both servers (2003 and 2008) point to the same database on a stand-alone SQL server.

I was able to work around this problem by optimizing the problem PDF file, which I am sure changed the byte sequence around the "cut-off point". But I still don't get what exactly causes the problem (and thus can't prevent this from happening in the future).
 

cyberia

Platinum Member
Oct 22, 1999
2,535
0
0
If you use a packet sniffer like WireShark or an in-browser tool like IEWatch or Fiddler you can look at the server response headers, including the content type, content length, and response body.

I just tried that using the Live HTTP Headers extension in FF. Here is what I get:

Code:
HTTP/1.1 200 OK
Cache-Control: private
Transfer-Encoding: chunked
Content-Type: text/html
Content-Encoding: gzip
Vary: Accept-Encoding
Server: Microsoft-IIS/7.5
Content-Disposition: attachment;filename=test123.pdf
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Wed, 30 May 2012 18:23:43 GMT

Nothing out of ordinery to my eye. Or should the Content-Type be something else, like application/pdf?
 

cyberia

Platinum Member
Oct 22, 1999
2,535
0
0
Maybe some sort of difference in the IIS configuration?

That's what I am thinking, but I don't know where to look. I am guessing that IIS 7 under Server 2008 is locked down tighter than IIS 6 on Server 2003.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
> Content-Type: text/html

What is the content-type from the 2003 server? I'd expect something like:
Content-type: application/pdf
 

cyberia

Platinum Member
Oct 22, 1999
2,535
0
0
> Content-Type: text/html

What is the content-type from the 2003 server? I'd expect something like:
Content-type: application/pdf

Nope, the same thing. Same Framework version too. But there is no Content-Encoding header. Hmm...

HTTP/1.1 200 OK
Date: Wed, 30 May 2012 19:10:49 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Content-Disposition: attachment;filename=test123.pdf
Transfer-Encoding: chunked
Cache-Control: private
Content-Type: text/html
 

cyberia

Platinum Member
Oct 22, 1999
2,535
0
0
Yep, that was it: I had to disable dynamic content compression for this web application in the IIS settings.

Thank you for nudging me toward the right path.
 

Mark R

Diamond Member
Oct 9, 1999
8,513
14
81
What browser were you using?

This is a known bug in IE - downloaded files are corrupted when dynamic compression is switched on, and the content type is anything other than "application/octet-stream".

But browsers like chrome, firefox and safari will download the files correctly.
 

cyberia

Platinum Member
Oct 22, 1999
2,535
0
0
What browser were you using?

This is a known bug in IE - downloaded files are corrupted when dynamic compression is switched on, and the content type is anything other than "application/octet-stream".

But browsers like chrome, firefox and safari will download the files correctly.

I actually had that issue with that particular file (but not others) in all three browsers.
 

Ileana

Junior Member
Jul 29, 2014
2
0
0
I have exactly the same problem, what I have noticed is that the PDF file versión that can't be retrieved is higher than 1.4 (Acrobat 5.x) , for that version there is no problem retrieving the PDF file. Am I right? how can I solve it?
 

cyberia

Platinum Member
Oct 22, 1999
2,535
0
0
I have exactly the same problem, what I have noticed is that the PDF file versión that can't be retrieved is higher than 1.4 (Acrobat 5.x) , for that version there is no problem retrieving the PDF file. Am I right? how can I solve it?
Wow, this is an oldie - and welcome to AT. I haven't been to the forums in a long while too.

I don't remember the specifics, but here is what I posted as the solution at the time:
I had to disable dynamic content compression for this web application in the IIS settings.
Hope this helps.
 

Ileana

Junior Member
Jul 29, 2014
2
0
0
Wow, this is an oldie - and welcome to AT. I haven't been to the forums in a long while too.

I don't remember the specifics, but here is what I posted as the solution at the time:

Hope this helps.
Yes I know it was an old post, sorry shame on me ...lol.. Ok, I will try what you say and let you know, thanks a lot !
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |