• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2594
  • Last Modified:

Load Report Failed

I have a .Net application that uses Crystal Reports v10.  It prints a lot of reports automatically throughout the day.  It'll run fine for a while, sometimes days - printing reports just fine, then all of a sudden it'll stop working.  The error says "Load Report Failed".  The application runs as a service, with the error messsages written to the event log.  The only way to get it to work again is to unload the service and reload it.  Then it'll work fine.  

The application was originally written with the RPT as an embedded resource.  In trying to resolve the problem I changed that to reference an external file but I still have the same problem.  This occurs on multiple systems.

Can anyone help with this?  I'm thinking it has to do with the fact that I print so may reports in a day (maybe 100+).  Everything must be installed correctly or it wouldn't ever work at all.  

Printing is done via the printInvestigationSheet method, which I have copied below (C#):

public bool printInvestigationSheet(string orderID, string store, DateTime OrderDate, DataAccessLayerBaseClass DBLayer) {
      try {
            ReportDocument crReportDocument = new ReportDocument();
            crReportDocument.Load(Application.StartupPath + @"\investigation.rpt");
            foreach (Table crTable in crReportDocument.Database.Tables) {
                  TableLogOnInfo crTableLogOnInfo = crTable.LogOnInfo;
                  crTableLogOnInfo.ConnectionInfo.ServerName = Preferences.DBServer;
                  crTableLogOnInfo.ConnectionInfo.DatabaseName = Preferences.DBName;
                  crTableLogOnInfo.ConnectionInfo.UserID = Preferences.databaseUserID;
                  crTableLogOnInfo.ConnectionInfo.Password = Preferences.databasePassword;
                  crTable.Location = crTableLogOnInfo.ConnectionInfo.DatabaseName + ".dbo." + crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1);
            crReportDocument.RecordSelectionFormula = "{Orders.OrderID} = '" + orderID + "' and {Orders.Store} = '" + store + "' and {Orders.OrderDate} >= #" + OrderDate.ToString("MM/dd/yyyy") + "#";
            crReportDocument.PrintOptions.PrinterName = Preferences.defaultPrinter;
            crReportDocument.PrintToPrinter(1, true, 0, 0);
            // If the document printed successfully, set a flag in the database indicating so
            DBLayer.setInvestigationSheetPrinted(orderID, store, OrderDate);
            return true;
      } catch (Exception e) {
            // This is where the "Load Report Failed" error is raised and written to the eventlog.
            MessageHandler.getInstance.writeError("Unable to print investigation sheet for OrderID=" + orderID + ", store=" + store + ", OrderDate=" + OrderDate.ToString("MM/dd/yyyy") + ".\n\nThe specific error message is:\n\n" + e.Message);
                        return false;
1 Solution
What errors do you see other than the LOAD FAILED?

Is there a report that always seems to fail?

Do all reports use the same database and the same connection method?

craigsweetAuthor Commented:
I only get "Load Report Failed".

There is only one report in the application.  This is an order processing application.  My application makes a decision on about 85% of the orders.  Those it cannot decide upon go to Loss Prevention, with a printout, for further investigation.  So, there is only one database (of orders).  Even though the preferences are read via the Preferences class' accessor methods, they don't change.  

Note:  The application is designed to gracefully handle errors and move on.  I set a flag in the database when a report is printed (the setInvestigationSheetPrinted method above does that, so that when I stop and restart the service I can tell which reports have not printed (i.e. flag is not set but should be).  Since those reports ALWAYS print when I stop and restart the service I know there is nothing wrong with the record in the dabase, the selection formula, etc.  

I really think this has something to do with either the amount of reports I'm printing but it would be stupid for CR to have a limitation on that.  Note that this has never happened in development since I simply don't print large numbers of reports.  I may print 10 or 15 here or there, but even that's rare.  Even in production it can happen after one day, one week, or one month or longer.  It usually happens every few days currently.  Also, I'm now on a new server.  I was hoping the move from NT to 2003 would solve this but it hasn't.

This error started when I migrated to Visual Studio 2003 (I'm using VS 2005 now so it's been ongoing for a long time).  

I'm guessing that this might be a resource/memory leak issue, try adding this after printing the report:

craigsweetAuthor Commented:
OK, that worked.  That was an amateurish mistake :-)

I still don't know why the original code, which instantiated the embedded class, didn't work but who cares.  I'll worry about that another day.  I only changed the code to load from disk recently and forgot to close it.  

I just wrote a test app that loaded the report 100 times in a for loop.  It fails everytime at the 75 th iteration.  When it does fail, it never loads again until you end the program.  Not sure why the garbage collector doesn't help out but, again, who cares at this point.

Thanks for your help.
thanks a lot janmarini... After going through numerous web sites and hundreds of useless solutions, this helped me...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now