Solved

Load Report Failed Exception, the second time any report is loaded, Crystal Report for Visual Studio 2010

Posted on 2011-02-11
8
1,361 Views
Last Modified: 2012-06-27
Hello -

I have a report that runs successfully the very first time I run it through the debugger, then any subsequent attempt to run the report generates a 'Load Report Failed' Exception. Why is this?
I have tried it with a report created in Crystal XI r 2, then with a report created wiht the Crystal Reports embedded in Visual Studio 2010, same error.

Closing Visual Studio resets the application and the report will run one time again successfully.
ReportDocument cryRpt = new ReportDocument();
         frmReportViewer myReportViewer = new frmReportViewer();
         TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
         TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
         ConnectionInfo crConnectionInfo = new ConnectionInfo();
         Tables CrTables;

         ParameterFieldDefinitions crParameterFieldDefinitions;
         ParameterFieldDefinition crParameterFieldDefinition;
         ParameterValues crParameterValues = new ParameterValues();
         ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
            
            //Check Message Result to Save or Cancel
        
             filename = Application.StartupPath + "\\" + "TestCR.rpt";
         
        
         try
         {
             cryRpt.Load(filename);

Open in new window

0
Comment
Question by:Marc_Johnson
  • 5
  • 3
8 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 34874335
What is the rest of the code?

What code do you use when you close the viewer?

mlmcc
0
 

Author Comment

by:Marc_Johnson
ID: 34874926
I posted the rest of the code, I had left it off because it never gets there. Everything fails when I attempt to Load the report.

I do not have any code for when the viewer closes.
The viewer is a Crystal Reports Viewer on it's own form
private void btnPrintSched_Click(object sender, EventArgs e)
     {
         String messageString;
         String filename = "";

         DialogResult saveData = DialogResult.No;

         string EmployeeName = (string)scheduleDataGridView.CurrentRow.Cells["FullName"].Value;       

         messageString = "Choose YES to print schedule for " + EmployeeName.ToUpper()  + ". Choose NO to print the entire group";                
         
         saveData = MessageBox.Show(messageString, "Print Individual or All Show Schedules?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

         if (saveData == DialogResult.Cancel)
             return;

         //---
         // Report Set Up Info
         //--------
        
         ReportDocument cryRpt = new ReportDocument();
         frmReportViewer myReportViewer = new frmReportViewer();
         TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
         TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
         ConnectionInfo crConnectionInfo = new ConnectionInfo();
         Tables CrTables;

         ParameterFieldDefinitions crParameterFieldDefinitions;
         ParameterFieldDefinition crParameterFieldDefinition;
         ParameterValues crParameterValues = new ParameterValues();
         ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
            
            //Check Message Result to Save or Cancel
         if(saveData == DialogResult.Yes)
         {
             //filename = @"\\lvccmsapps1\reg\RegistrationReports_DotNet\ScheduleIndividual.rpt";
             filename = Application.StartupPath + "\\" + "TestCR.rpt";
         }
         else if(saveData == DialogResult.No)
         {
             //filename = @"\\lvccmsapps1\reg\RegistrationReports_DotNet\ScheduleEvent.rpt";
             filename = Application.StartupPath + "\\" + "TestCR.rpt";
         }

         try
         {

             cryRpt.FileName = filename;
             cryRpt.Load(filename);

             // crConnectionInfo.ServerName = "YOUR SERVER NAME";
             // crConnectionInfo.DatabaseName = "YOUR DATABASE NAME";
             crConnectionInfo.UserID = "UserID";
             crConnectionInfo.Password = "Password";

             CrTables = cryRpt.Database.Tables;
             foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
             {
                 crtableLogoninfo = CrTable.LogOnInfo;
                 crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                 CrTable.ApplyLogOnInfo(crtableLogoninfo);
             }

             // SET UP REPORT PARAMETERS 
             //By Default sets the parameters for whole show
             crParameterDiscreteValue.Value = (int)scheduleDataGridView.CurrentRow.Cells["EventID"].Value;
             crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
             crParameterFieldDefinition = crParameterFieldDefinitions["EventID"];
             crParameterValues = crParameterFieldDefinition.CurrentValues;

             if (saveData == DialogResult.Yes)
             {
                 //Over writes parameters with ind Schedule if chosen
                 crParameterDiscreteValue.Value = (int)scheduleDataGridView.CurrentRow.Cells["ScheduleID"].Value;
                 crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
                 crParameterFieldDefinition = crParameterFieldDefinitions["ScheduleID"];
                 crParameterValues = crParameterFieldDefinition.CurrentValues;
             }

             crParameterValues.Clear();
             crParameterValues.Add(crParameterDiscreteValue);
             crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

             //myReportViewer.crystalReportViewer1.ReportSource = cryRpt;
             myReportViewer.crystalReportViewer1.ReportSource = filename;

             myReportViewer.crystalReportViewer1.Refresh();
             myReportViewer.Show();
         }
         catch (Exception Ex)
         {
             MessageBox.Show(Ex.Message);
         }
         finally
         {
              cryRpt.Dispose();
             
         }

     }

Open in new window

0
 
LVL 100

Expert Comment

by:mlmcc
ID: 34875527
I am not familiar with how the TRY - CATCH - FINALLY works

My understanding is that it is basically used to catch the errors so once you enter the TRY part if an error occurs then the CATCH part is run.

If no errors occur does the FINALLY part then run?

Have you closed the viewer?

I assume you click the button
The report runs
WHen you click the button again it prompts for the all or one then you get the error?

mlmcc
0
 

Author Comment

by:Marc_Johnson
ID: 34875972
Yes, that is how the TRY CATCH FINALLY works, but it is not the issue. I could boil the code down to the simplest items, which would be getting the report file location and then loading the report, which is where the error occurs.

When I close the form viewer I click the X in the corner, the very first tiem through the debugger the report viewer opens and runs. Any subsequent calls and I get the Failure to Load Error no matter which report I try from the select options.

I have simpler code in another location that attempts to open a report on button click and it doesn't not work more than once there either.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Marc_Johnson
ID: 34875978

private void testReportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ReportDocument cryRpt = new ReportDocument();
           frmReportViewer myReportViewer = new frmReportViewer();
           string filename = Application.StartupPath + "\\" + "TestCR.rpt";

            cryRpt.Load(filename);
           myReportViewer.crystalReportViewer1.ReportSource = cryRpt;
           myReportViewer.crystalReportViewer1.Refresh();
           myReportViewer.Show();
           
         
        }

Open in new window

0
 
LVL 100

Expert Comment

by:mlmcc
ID: 34876971
I asked only because I had similar issues which were solved by ensuring when the form closed and before abnother report was run that the report object was deleted and set to nothing.  That was in VB6.  Since the finally part runs the dispose should cleanup the report object.

i wonder if you have to do the same with the report viewer.

mlmcc
0
 

Accepted Solution

by:
Marc_Johnson earned 0 total points
ID: 34889893
I am not sure why, but the software will now launch one report after the other. I didn't change any code or settings on the ReportViewer.
Problem solved. Perhaps it was something else conflicitn on my system.

I appreciate your questions and observations
0
 

Author Closing Comment

by:Marc_Johnson
ID: 34932111
The issue seemed to have resolved itself
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now