How to Cache Crystal Report Results

Hi Experts,

I am currently using Crystal Report in ASP.NET page. I use CrystalReportViewer object to display result to user. My problem is, when the user try to export report or change page, the report will be reload and query database again. If the query spends a lot of time, user will take very long time when change page or export report. Is there any way to cache the results?

I am also trying to use CrystalReportSource object. It has cache feature, but I don't know how to pass over the user defined parameters to it at runtime. If anyone can show me a sample. It will be really appreciated.

Here are some more details.

Crystal Report :
The Crystal Report is rpt file. Parameters are passed from ASP.NET page to RPT file. The parameters are used as input of stored procedure. Out put of stored procedure is a table.

ASP.NET Page :
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="False" GroupTreeImagesFolderUrl="" Height="1202px"
                OnInit="CrystalReportViewer1_Init" ToolbarImagesFolderUrl="" ToolPanelWidth="200px" Width="1104px"
                ToolPanelView="None" EnableDatabaseLogonPrompt="False" EnableParameterPrompt="False" OnError="CrystalReportViewer1_Error" 
                ReuseParameterValuesOnRefresh="True" OnLoad="CrystalReportViewer1_Load" Visible="true" />

Open in new window

Back End Code :
// Click button to show report
protected void btnViewReport_Click(object sender, EventArgs e)

// The event will be trigged whenever user click 'next page' or export report
protected void CrystalReportViewer1_Load(object sender, EventArgs e)

private void LoadReport()
                ReportDocument rpt = new ReportDocument();
                rpt.SetDatabaseLogon(conn.UserID, conn.Password, conn.DataSource, conn.InitialCatalog, false);
                rpt.SetParameterValue("@loginname", (HttpContext.Current == null) ? "" : User.Identity.Name);
                rpt.SetParameterValue("@strDate", DateTime.ParseExact(pickStrDate.Value, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
                rpt.SetParameterValue("@endDate", DateTime.ParseExact(pickEndDate.Value, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
                rpt.SetParameterValue("@dateRange", -1);
                rpt.SetParameterValue("@companyID", (lstCompany.SelectedIndex == -1) ? 0 : int.Parse(lstCompany.SelectedValue));
                CrystalReportViewer1.ReportSource = rpt;
            catch (Exception)

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Add the ReportDocument instance to a session variable and set CrystalReportViewer1.ReportSource to use this variable instead of using ReportDocument instance directly

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
To pass parameters this link has code that shows how.  About 1/4 the way through the article

David_zuAuthor Commented:
It works great. Thank you for your suggestion.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.