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,392 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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
 

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 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