Running & Exporting Same Crystal Report

Posted on 2009-06-29
Last Modified: 2013-11-15
Hi there,
I have a report which takes a parameter ScriptRef and return the result. I am using the code below to export that report as an HTML to a web page. Code works fine for running this report once. But I'd like to run the same report more than once (in a loop) and export the content to a stream and finally flush that combined stream in a Response.End function.
When I run the web application in a debug mode I found out that it would just run the report once and then give an error when it iterates through the loop the second time.

'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'

The reason I want to run multiple reports in one final stream is so that user can do a batch print.

Any help will be highly appreciated.


protected override void OnPreRender(EventArgs e)


        string Script_Reference = "241-002-002";

        string userName = ConfigurationManager.AppSettings["UserID"];

        string password = ConfigurationManager.AppSettings["Password"];

        string serverName = ConfigurationManager.AppSettings["ServerName"];

        string databaseName = ConfigurationManager.AppSettings["DatabaseName"];

        string reportName1 = "";

        // using System.IO

        MemoryStream oStream2 = new MemoryStream(); 


        Response.Buffer = true;

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

        for (int i = 0; i < 2; i++)


            Label1.Text += ": Hi ";

            if (Script_Reference != null)




                    lblScriptRef.Text = Script_Reference;

                    Label1.Text = "";// "Script_Reference";

                    reportName1 = AccessScript.GetScriptType(Script_Reference).Trim() + ".rpt";

                    report.Load("Path\\" + reportName1);

                    report.FileName = "Path\\" + reportName1;

                    report.SetParameterValue("Script_Reference", Script_Reference.Trim());

                    report.SetDatabaseLogon(userName, password, serverName, databaseName);

                    //CrystalReportViewer1.ReportSource = report;

                    MemoryStream oStream ;

                    oStream = (MemoryStream)






                    oStream = null;

                    Script_Reference = "241-002-003";



                //catch (Exception ex)


                //    Label1.Text = "Please select Script from the prescription screen. " + ex.Message + " Report Name: " + reportName1;


                //CrystalReportViewer1.ReportSource = report;






Open in new window

Question by:OrionPMS

Accepted Solution

Bob Hoffman earned 500 total points
ID: 24740185
crystal creates temp .rpt files that are alive on your web servers hard drive until you dispose of the report file. Try disposing of the report file after you close it. Then recreate it at the top of your loop.

Author Comment

ID: 24743469
Thank you for your reply.

I used the report.Dispose() method and now I am not getting the error!

But now I've got another problem the final stream (ostream2) displays both report on top of each other. Is there any way I could add a page break at the end of the loop so that the next report is displayed after the first one.


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Javascript in a user control not working 17 65
Handle null when using linq in this line 1 26
Error in page 3 45
Name space syntax error 12 41
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now