Solved

Load report failed

Posted on 2009-04-07
13
4,391 Views
Last Modified: 2013-11-15
Hello,

I am receiving a "Load report failed" error when i try viewing reports on my website that contains embedded Crystal reports. When i begun receiving these errors, cleared out the temp folder "C:\WINDOWS\Temp", assigned modify, read write rights to IIS/WPG, set  impersonate="false" in my web config file, and it still didn't help and my code also caters for closing and disposing the report and utilizes the garbage collector. So i restarted IIS, which did do the trick, but is there any other way of prevent this error from occuring again, instead of restarting IIS, since my website utilizes sessions, and session values will be lost.
public ReportDocument myReport;

protected void Page_Unload(object sender, EventArgs e)

{

        if (myReport!= null)

        {

            myReport.Close();

            myReport.Dispose();

        }

        GC.Collect(); 

}

Open in new window

0
Comment
Question by:WalterRautenbach
  • 7
  • 6
13 Comments
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24085366
that is because you have reached maximum limit of report. You can use following code for that. for further explanation, have a look at following links

http://www.crystalreportsbook.com/Forum/forum_posts.asp?TID=1205

public class ReportFactory

{

      public static Hashtable reportTable = new Hashtable();

     

      public static void CreateReport(string key, string path)

      {

            ReportDocument report = new ReportDocument();

            report.Load(path);

            reportTable.Add(key, report);

      }

  

      public static void CloseReport(string key)

      {

            ((ReportDocument)reportTable[key]).Close();

            ((ReportDocument)reportTable[key]).Dispose();

            reportTable.Remove(key);

      }

}

 

Open in new window

0
 

Author Comment

by:WalterRautenbach
ID: 24085739
Thank you for the comment, what does the "key" reference, i understand the "path" is the path of the .rpt file.
0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24085797
actually that was not a good and full example, let me give you class code which I am using in my production. You can generate one class file for this and use it.



using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Collections.Generic;

using CrystalDecisions.CrystalReports.Engine;

using System.IO;

using System.Text;

using System.Web.Caching;

using System.Diagnostics;
 

/// <summary>

/// Summary description for ReportDocumentFactory

/// </summary>

public class ReportDocumentFactory

{
 

	//Crystal printJobLimit key is in registry:

	//HKEY_LOCAL_MACHINE\SOFTWARE\Crystal Decisions\10.2\Report Application Server\Server\PrintJobLimit

	const int CRYSTAL_PRINT_JOB_LIMIT = 75; //default value is 75, it must by sincronized with registry!
 

	const string REPORT_DOCUMENT_CAHE_KEY = "ReportDocumentQueue";
 

	private Dictionary<string, ReportDocumentInfo> docList;
 
 

	public ReportDocumentFactory(Cache cache)

	{

		try

		{

			docList = (Dictionary<string, ReportDocumentInfo>)cache[REPORT_DOCUMENT_CAHE_KEY];

		}

		catch (InvalidCastException ex)

		{

			//if generic dictionary is compiled dinamically, we must clean report cache.

			//This has a problem, because the processed reports are not disposed, this case

			//should not happen to.

			cache.Remove(REPORT_DOCUMENT_CAHE_KEY);

			docList = null;

		}
 

		if (docList == null)

		{

			docList = new Dictionary<string, ReportDocumentInfo>(CRYSTAL_PRINT_JOB_LIMIT);
 

			cache.Add(REPORT_DOCUMENT_CAHE_KEY, docList, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 20, 0),

				CacheItemPriority.AboveNormal, new CacheItemRemovedCallback(this.CacheRemovedCallback));

		}

	}
 

	public string Add(ReportDocument reportDoc)

	{

		Debug.WriteLine("Add() called.");
 

		if (docList.Count + 1 >= CRYSTAL_PRINT_JOB_LIMIT)

		{

			Debug.WriteLine("Add() CRYSTAL_PRINT_JOB_LIMIT Reached.");
 

			try

			{

				//dequeue de old one (FIFO)

				List<ReportDocumentInfo> rInfoSortList = new List<ReportDocumentInfo>(docList.Values);
 

				rInfoSortList.Sort(delegate(ReportDocumentInfo rInfo1, ReportDocumentInfo rInfo2)

									{

										return DateTime.Compare(rInfo1.Date, rInfo2.Date);

									});
 

				Remove(rInfoSortList[0].Key);

			}

			catch (Exception e)

			{

				//TODO: log

				Debug.WriteLine("Add() error: " + e.Message);
 

				try

				{

					Remove(docList.Keys.GetEnumerator().Current.ToString());

				}

				catch { }

			}

		}
 

		string key = Guid.NewGuid().ToString();
 

		docList.Add(key, new ReportDocumentInfo(key, reportDoc));
 

		return key;

	}
 

	public void Remove(string key)

	{

		Debug.WriteLine("Remove() called.");
 

		if (key != null)

		{

			try

			{

				ReportDocumentInfo reportInfo = docList[key];
 

				DisposeReportDocument(reportInfo);
 

				docList.Remove(key);

			}

			catch (Exception e)

			{

				Debug.WriteLine("Remove() error: " + e.Message);

			}

		}

		else

		{

			Debug.WriteLine("Remove() error: null key");

		}

	}
 

	public bool Contains(string key)

	{

		return docList.ContainsKey(key);

	}
 

	public ReportDocument GetValue(string key)

	{

		ReportDocumentInfo value = null;

		if (docList.TryGetValue(key, out value))

		{

			if (value != null)

				return value.ReportDoc;

			else return null;

		}

		else

		{

			return null;

		}

	}
 

	protected void DisposeReportDocument(ReportDocumentInfo reportInfo)

	{

		try

		{

			if (reportInfo != null)

			{

				//Need to dispose document, crystal has a limit for number of loaded reports

				reportInfo.ReportDoc.Close();

				reportInfo.ReportDoc.Dispose();

			}

		}

		catch (Exception e)

		{

			//TODO: log

			Debug.WriteLine("DisposeReportDocument() error: " + e.Message);

		}

	}
 

	//Release crystal resources when cache is clean

	public void CacheRemovedCallback(string key, Object value, CacheItemRemovedReason reason)

	{

		Debug.WriteLine("CacheRemovedCallback() called, reason: " + reason.ToString());
 

		try

		{

			if (docList != null)

			{

				Debug.WriteLine("CacheRemovedCallback() cleaning ressources " + docList.Count);
 

				Dictionary<string, ReportDocumentInfo>.ValueCollection valueColl = docList.Values;
 

				foreach (ReportDocumentInfo reportDocInfo in valueColl)

				{

					DisposeReportDocument(reportDocInfo);

				}

			}

		}

		catch

		{

			Debug.WriteLine("CacheRemovedCallback() error.");

		}

	}

}

Open in new window

0
 
LVL 31

Accepted Solution

by:
RiteshShah earned 500 total points
ID: 24085837
this is what I used in my ASPX page's code behind. Page's init event (not load event)


//class which I just gave

        ReportDocumentFactory reportDocumentFactory;

        //instance of report

        ReportDocument myDocument;

        //my dataset 

        ReportInvoice rptInvoice = new ReportInvoice();

        

        reportDocumentFactory = new ReportDocumentFactory(this.Cache);

        myDocument = null;
 

        string key = (string)ViewState["reportKey"];
 

        if (key != null)

        {

            myDocument = this.reportDocumentFactory.GetValue(key);

        }
 
 

        if (myDocument == null)

        {

            myDocument = new ReportDocument();
 
 

            myDocument.Load(Server.MapPath("Report2.rpt"));

            myDocument.SetDataSource(ds);
 

            string newKey = this.reportDocumentFactory.Add(myDocument);

            ViewState["reportKey"] = newKey;

        }
 

        CrystalReportViewer1.ReportSource = myDocument;

        CrystalReportViewer1.DataBind();

Open in new window

0
 

Author Closing Comment

by:WalterRautenbach
ID: 31567395
Thank you!!!
0
 

Author Comment

by:WalterRautenbach
ID: 24086667
What is the namespace for ReportDocumentInfo? I am getting the following error '"The type or namespace name 'ReportDocumentInfo' could not be found (are you missing a using directive or an assembly reference" when i try compiling your code.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 31

Expert Comment

by:RiteshShah
ID: 24086719
no namespace for that. You have to create on separate class for the code I gave you in post id 24085797. I have created ReportDocumentFactory.cs file under my APP_code folder of my website.
0
 

Author Comment

by:WalterRautenbach
ID: 24086862
i have created a separate class, but i get the following error "The type or namespace name 'ReportDocumentInfo' could not be found (are you missing a using directive or an assembly reference"
0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24086891
where did you put that class? and what is the name you gave to that class? I would recommend you to put it under app_code folder in root of your web directory. and give it a name ReportDocumentFactory.cs. Once you generate ReportDocumentFactory.cs file, copy my code which is in post # 24085797 and paste it in ReportDocumentFactory.cs
0
 

Author Comment

by:WalterRautenbach
ID: 24087233
I created the class within the root directory and the class is within the App_Code folder. Is the 'ReportDocumentInfo'  a variable which supposed to be declared with the class? Dictionary<string, string> so I presume 'ReportDocumentInfo'  is a string?
0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24087322
reportdocumentinfo is another class and again needs to be save under app_code folder with name ReportDocumentInfo.cs

sorry I forget to attach its code before. below given is the code. Moreover, don't put any class under direct root folder
using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Collections.Generic;

using CrystalDecisions.CrystalReports.Engine;

using System.IO;

using System.Text;

using System.Web.Caching;

using System.Diagnostics;
 

/// <summary>

/// Summary description for ReportDocumentInfo

/// </summary>

public class ReportDocumentInfo

{

    private string key;

    private ReportDocument reportDocument;

    private DateTime date;
 

    public ReportDocumentInfo(string key, ReportDocument reportDocument)

    {

        this.key = key;

        this.reportDocument = reportDocument;

        this.date = DateTime.Now;

    }
 

    public ReportDocument ReportDoc

    {

        get

        {

            return this.reportDocument;

        }

        set

        {

            this.reportDocument = value;

        }

    }
 

    public DateTime Date

    {

        get

        {

            return this.date;

        }

        set

        {

            this.date = value;

        }

    }
 

    public string Key

    {

        get

        {

            return this.key;

        }

    }

}

Open in new window

0
 

Author Comment

by:WalterRautenbach
ID: 24087548
thank you, makes much more sense now. Another thing i want to ask you is, when you instantiate the class ReportDocumentFactory, was it not suppose  to be as follows
ReportDocumentFactory reportDocumentFactory=new ReportDocumentFactory (cache);
since the class ReportDocumentFactory expects an argument.

I have added your code and it is still not functional, therefore i am asking this question.
0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24087616
yes you can do like that also

ReportDocumentFactory reportDocumentFactory = new ReportDocumentFactory(this.Cache);

in aspx code I gave you, I have delare the class first and that instantiated. but you can do it in same line.

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
C# Export DataGridView 4 38
Paging GridView 7 32
fomat Json objects 6 15
IO.FileSystemWatcher dies when used in Powershell 1 13
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
I recently went through setting up a JasperReports Server using the AWS EC2 instance, and this article will cover some basic administration tasks I had to perform.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

16 Experts available now in Live!

Get 1:1 Help Now