MS ReportViewer Cause Application Error
-
I'm using VS2005 with MSAcsess and MS ReportViewer to genearate a report. It work perfectly in my development environment. When i try to deploy the application to Virtual PC with a clean environment, it work fine. The application will hang when user open the report form and close and reopen (sometime happen on the third time)again the report form. Below is the code. And also i found out if user close the form in PrintLayout Mode. I must cancel the report rendering in form close event.
this.reportViewer1.CancelRendering(5000);
Else the program will hanged forever when user click PrintLayout button.FormReport frm = new FormReport(); this.Cursor = Cursors.WaitCursor; try { frm.ShowReport(sqlStatement + frm2.QueryString + " " + order , reportName); frm.ShowDialog(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { //frm.Dispose(); this.Cursor = Cursors.Default; } private void ShowReport(string reportName, ReportsDS reportDS) { if (reportDS.Report.Rows.Count < 1) { MessageBox.Show("No records found. Please import data into system."); this.Close(); } ReportDataSource reportDataSource = new ReportDataSource(); reportDataSource.Name = "ReportsDS_Report"; reportDataSource.Value = reportDS.Report; this.reportViewer1.LocalReport.ReportEmbeddedResource = reportName; this.reportViewer1.LocalReport.DataSources.Add(reportDataSource); this.reportViewer1.RefreshReport(); } private void FormReport_FormClosing(object sender, FormClosingEventArgs e) { try { this.reportViewer1.CancelRendering(5000); } catch (Exception ex) { MessageBox.Show(ex.Message); } }