If this is a web app, make sure the report is in session. See the following from KBA 1985571
- Below is a complete code that describes how to ensure the report is in session:
public partial class Reports : RAPPBasePage
{
private ReportDocument crReportDocument;
protected override void Page_Init(object sender, EventArgs e)
{
//connect method to master event
base.Page_Init(sender, e);
}
protected override void Page_Load(object sender, EventArgs e)
{
base.Page_Load(sender, e);
if (IsPostBack) // post back event, check if report is in session if it is view it.
{
crReportDocument = ReportDocument)Session["Report"];
// Now send the report to the viewer
CrystalReportViewer1.ReportSource = crReportDocument;
}
}
protected void butReport_Click(object sender, EventArgs e)
{
// code based on customer's examples
If(Session["Report"]==null) // Report is not in session (previously loaded) so load report, set params, view and place in session
{
crReportDocument = new ReportDocument();
crReportDocument.Load(Server.MapPath("MyTestReport.rpt"));
crReportDocument.SetDatabaseLogon("User", "Password", "Server", "Database");
crReportDocument.SetParameterValue("LocationId", fwsuser.currentLocation);
Session.Add(“Report”, crReportDocument);
CrystalReportViewer.ReportSource = crReportDocument;
}
else // Report is already loaded and in session so use it also means we never reload the report
{
crReportDocument = (ReportDocument)Session["Report"];
// Now send the report to the viewer
CrystalReportViewer1.ReportSource = crReportDocument;
}
//// How I would do it to so report is reloaded when ever button is pressed (IE Refreshing report, or load a different report if option
present)
// crReportDocument = new ReportDocument();
// crReportDocument.Load(Server.MapPath("Report_To_Load"));
// crReportDocument.SetDatabaseLogon("UserID", "UserPassword", "ServerName", "DatabaseName");
// crReportDocument.SetParameterValue("LocationId", fwsuser.currentLocation);
// Session.Add(“Report”, crReportDocument);
// CrystalReportViewer.ReportSource = crReportDocument;
}
protected void Page_UnLoad(object sender, EventArgs e)
{
try
{
crReportDocument.Close();
crReportDocument.Dispose();
}
catch { }
}
}