Solved

Running & Exporting Same Crystal Report

Posted on 2009-06-29
3
553 Views
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.

Regards,
Fawad.

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.Clear();
        Response.Buffer = true;
        //Response.ContentType = "application/pdf";
        for (int i = 0; i < 2; i++)
        {
            Label1.Text += ": Hi ";
            if (Script_Reference != null)
            {
                //try
                //{
                    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)
        report.ExportToStream(
        CrystalDecisions.Shared.ExportFormatType.HTML40);
                    oStream.WriteTo(oStream2);
                    oStream.Close();
                    oStream.Dispose();
                    oStream = null;
                    Script_Reference = "241-002-003";
                    report.Close();
 
                //}
                //catch (Exception ex)
                //{
                //    Label1.Text = "Please select Script from the prescription screen. " + ex.Message + " Report Name: " + reportName1;
                //}
                //CrystalReportViewer1.ReportSource = report;
            }
        }
        Response.BinaryWrite(oStream.ToArray()); 
        Response.End();
    }

Open in new window

0
Comment
Question by:OrionPMS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Accepted Solution

by:
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.
0
 

Author Comment

by:OrionPMS
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.


Regards,
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Hi, In my previous Article  (http://www.experts-exchange.com/Database/Reporting/A_15199-Introduction-to-Microstrategy.html)I discussed some basic understanding of Microstrategy that how we can get in Intro of Microstrategy (MSTR). Now it's tim…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 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