ReportCacheMode not working ?

Stimulsoft Reports.NET discussion
Post Reply
Hansjoerg Meyer
Posts: 7
Joined: Tue May 18, 2010 3:39 am
Location: Switzerland

ReportCacheMode not working ?

Post by Hansjoerg Meyer »

The Result of a analysis we produce is a huge dataset, which is too big to load into memory.
We tried to split it off and build several smaller dtatasets and reports.
The smaller reports we want to rejoin to the final report using ReportCacheMode = On.

During report creation we always get an OutOfMemoryException.
Does ReportCacheMode not work in such a scenario ?

Code: Select all

//---  configure ReportCache
StiOptions.Engine.ReportCache.LimitForStartUsingCache = 3000;
StiOptions.Engine.ReportCache.AmountOfQuickAccessPages = 3000;
StiOptions.Engine.ReportCache.CachePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

StiReport mainReport = new StiReport();
mainReport.Load(fileNameReportKontoauszug);
mainReport.ReportCacheMode = StiReportCacheMode.Auto;
mainReport.RenderedPages.Clear();
mainReport.NeedsCompiling = false;
mainReport.IsRendered = true;

while (recordStart < recordEnd)
{
	// fill partial datasets
	kontoauszug.Clear();
	kontoauszug.Dispose();
	kontoauszug = KontoauszugService.LoadKontoauszugByPersId(persIds);
         	
	// Render partial reports
	StiReport partialReport = new StiReport();
	partialReport.Load(fileNameReportKontoauszug);
	partialReport.DataSources.Clear();
	partialReport.RegData("Kontoauszug", kontoauszug);
	partialReport.RegData("ReportEnvironment", ReportEnvironment.GetReportEnvironment());
	partialReport.Dictionary.Synchronize();
	partialReport.ReportCacheMode = StiReportCacheMode.On;
	partialReport.RenderedPages.Clear();
	partialReport.Render();
		
	// Add rendered pages to mainreport
	mainReport.ReportCacheMode = StiReportCacheMode.On;
	foreach (StiPage reportPage in partialReport.RenderedPages)
	{
		reportPage.Report = partialReport;
		mainReport.RenderedPages.Add(reportPage);
	}		
}
mainReport.Show();
Kind regards
Hansjörg
Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

ReportCacheMode not working ?

Post by Brendan »

Hi,

From looking at your code sample, where are the following variables initalized with values?

Code: Select all

recordStart < recordEnd

Also, the values for these variables never seem to change within the loop, which would result in your code being stuck in an infinite loop. This would be one cause for the OutOfMemory exception.
Hansjoerg Meyer
Posts: 7
Joined: Tue May 18, 2010 3:39 am
Location: Switzerland

ReportCacheMode not working ?

Post by Hansjoerg Meyer »

Hi,

sorry i did'nt post the whole code.
There is an array acting as internal base for splitting the dataset in different parts.

Code: Select all

int recordStart = 0;
int recordEnd = 20000;
int recordStep = 1000;
while (recordStart < recordEnd)
{
  string[] persIds = new string[recordStep];
  int j1 = 0;
  for (int j = recordStart; j < (recordStart + recordStep); j++)
  {
    if (!string.IsNullOrEmpty(taktgeberPersonen[j]))
      {
	persIds[j1] = taktgeberPersonen[j];
      }
      j1++;
  }
  recordStart = recordStart + j1;

  // fill partial datasets
  ...
  .. 
If i set recordEnd to a value lower than 10'000 the code works properly and the report is ok.

Hansjörg
pavolbiacko2002
Posts: 1
Joined: Fri Jan 19, 2024 10:37 am

Re: ReportCacheMode not working ?

Post by pavolbiacko2002 »

Hi.

I have similar problem with OutOfMemoryException. Here is code we try to use in our company, but StiReportCacheMode.On is not working, as we supposed, it looks like it doesn't work at all. Or are we mising something? Problem is on line with Rendering (RenderAsync - Originaly Render, but thats not the problem, doesn't work in either case).

Could you help us with this, where can be the problem?

Thank you in advance!

Code: Select all

async protected static Task<StiReport> PrepareReport(
    string a_sLogPrefix,
    string a_sTemplateFileName,
    string a_sXMLDataFileName,
    string a_sReportAlias
)
{
    string v_sLogIdent = a_sLogPrefix + "PrepareReport";

    string v_sTimes = "";

    Stopwatch v_oTMElap = new Stopwatch();
    v_oTMElap.Start();

    //Stimulsoft.Report
    StiReport v_oReport = null;// GetReport("SimpleList.mrt");
                               //StiSerializeManager x;
                               //StiExportManager xx = null

    v_oReport = new StiReport();
    
    // I tried to get, what is the path for cache file
    var a = Stimulsoft.Report.StiOptions.Engine.ReportCache.CachePath;  // Empty string for some reason
    var x = v_oReport.ReportCachePath;  // Empty string for some reason

    v_sTimes = v_sTimes + "Init: " + v_oTMElap.ElapsedMilliseconds + " ms, ";

    v_oTMElap.Restart();
    
    // report1.setReportCacheMode(StiReportCacheMode.On);
    v_oReport.ReportCacheMode = StiReportCacheMode.On;

    v_oReport.Load(a_sTemplateFileName);
    v_sTimes = v_sTimes + "Load " + v_oTMElap.ElapsedMilliseconds + " ms, ";

    // ReportAlias
    if (a_sReportAlias != "")
        v_oReport.ReportAlias = a_sReportAlias;

    v_oTMElap.Restart();
    await v_oReport.RenderAsync();  // HERE IS THE PROBLEM!!! It fails, when file with data is somewhere between 50MB and 100MB, raises an exception OutOfMemoryException.

    v_sTimes = v_sTimes + "Render " + v_oTMElap.ElapsedMilliseconds + " ms.";

    return v_oReport;
}
#endregion

async private void button1_Click(object sender, EventArgs e)
{
    var filePath = @"...\data.mrt";  // hidden in this example
    var dataFilePath = @"...\file.xml";  // hidden in this example
    var exportFilePath = @"...\report.pdf";  // hidden in this example

    StiReport v_oRep = 
        await PrepareReport(
            "x",
            filePath,
            dataPath,  // this isn't used, because we are using another way to get the data, but that's not the problem
            "test");

    var stream = new MemoryStream();

    // v_oRep.ExportDocument(StiExportFormat.Pdf, stream);
    v_oRep.ExportDocument(StiExportFormat.Pdf, stream);

    // Save to Local Storage
    using (var fileStream = File.Create(exportFilePath))
    {
        stream.Seek(0, SeekOrigin.Begin);
        stream.CopyTo(fileStream);
    }

    MessageBox.Show($"File Created: {exportFileName}");
}
* There may be some mistakes or errors, because I erased some things just to capture the main thought what we are aiming to do with this script. Hopefully it won't be a problem. *
Lech Kulikowski
Posts: 6301
Joined: Tue Mar 20, 2018 5:34 am

Re: ReportCacheMode not working ?

Post by Lech Kulikowski »

Hello,

Please send us a sample project that reproduces the issue for analysis.

Thank you.
alirswhite
Posts: 1
Joined: Tue Jan 23, 2024 1:17 pm

Re: ReportCacheMode not working ?

Post by alirswhite »

This problem is really difficult to solve, I am also facing the same situation
Lech Kulikowski
Posts: 6301
Joined: Tue Mar 20, 2018 5:34 am

Re: ReportCacheMode not working ?

Post by Lech Kulikowski »

Hello,

Please send us a sample project that reproduces the issue for analysis.

Thank you.
Post Reply