Streaming a pdf to the browser..works in XP pro, window 2000 server, but not windows 2003 server

  • Thread starter Thread starter REB
  • Start date Start date
R

REB

This weekend I had to migrate a application from a windows 2000 server to a
windows 2003 server. Everything seems to be working except a button
contained on a page with a crystal report that is suppose to convert a
crystal report to pdf and stream it back to the users browser. It still
works in my development environment and on the windows 2000 server, but not
on window 2003 standard server.

Is there a setting in IIS 6.0 that I need to change to allow memory
streaming?

Here is the code first for the button and the function is calls:

private void Button1_Click(object sender, System.EventArgs e)

{

ConvertToPDF();

}

private void ConvertToPDF()

{

sqlSelectCommand1.CommandText = @"SELECT dbo.Bond.prin_name,
dbo.Bond.Issued_Bond_Num, dbo.Bond.type, dbo.Obligee.name,
dbo.Bond.bond_description, dbo.Bond.bond_amount, dbo.Bond.premium,
dbo.Bond.eff_date, dbo.Bond.expir_date, dbo.Obligee.state FROM dbo.Bond
INNER JOIN dbo.Obligee ON dbo.Bond.obligee_num = dbo.Obligee.obligee_num
WHERE (dbo.Obligee.state = '"+ TextBox1.Text +"') AND (dbo.Bond.status_bond
<= 2) Order by " + ddlSort.SelectedValue;

daBondState.Fill(dsBondState1);

BondState oRpt = new BondState();

oRpt.SetDataSource(dsBondState1);

System.IO.MemoryStream mystream = new System.IO.MemoryStream();

try

{

mystream =
(System.IO.MemoryStream)oRpt.ExportToStream(ExportFormatType.PortableDocForm
at);

}

catch(Exception ex)

{

Response.Write("There was an error exporting the report to PDF. Details:" +
ex);

}


HttpContext.Current.Response.ClearContent();

HttpContext.Current.Response.ClearHeaders();

HttpContext.Current.Response.ContentType = "application/pdf";

HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;
filename=BondbyUnitNum.pdf");

HttpContext.Current.Response.BinaryWrite(mystream.ToArray());

HttpContext.Current.Response.End();



}
 
What error are you getting on the 2003 box? Did you install the CR
binaries to run Crystal Reports there?
 
The reports themselves work fine and display on the webforms just fine. No,
I did not install anything beyond the msi created in VS.NET for my report
application.
 
Consider what happens if you get an exception - you still set the content
type to application/pdf, which will probably load the Acrobat pluging and
hang it.

You might want to try setting the content length as well, something like
this:

Response.AddHeader( "content-length", mystream.Length() );

Regards

John
 
That is a good idea with the content length I added it to the code.

However I still cannot get the reports to export. WHen the user clicks the
button that exports it just opens a new blank page. I should reinterate
that the very same code reinstalled on a windows 2000 server works perfect
and it also works fine in my devlopment environment running windows XP.

The installs for the windows 2000 and 2003 server used the exact same MSI
file to install.
 
Back
Top