We help IT Professionals succeed at work.
Get Started

How to Cache Crystal Report Results

David_zu
David_zu asked
on
443 Views
Last Modified: 2015-03-13
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)
        {
            LoadReport();
        }

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

private void LoadReport()
        {
            try
            {
                ReportDocument rpt = new ReportDocument();
                rpt.Load(Server.MapPath(@"~\Test.rpt"));
                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

Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2011
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE