Cashing issue

Stimulsoft Reports.NET discussion
Post Reply
shemein
Posts: 5
Joined: Fri Jan 13, 2017 1:11 am

Cashing issue

Post by shemein »

Hi,
I already have a report with 20000 records and 950 pages in the StiViewer. When I get the report the out of memory issue was coming up and when I added thecode below the memory issue vanished :
report.ReportCacheMode=StiReportCacheMode.On;
StiOptions.Engine.ReportCache.AmountOfProcessedPagesForStartGCCollect = 2; // default - 20
StiOptions.Engine.ReportCache.AmountOfQuickAccessPages = 5; // default - 50

but now I can't navigate between pages and it says that report is not found and brings the report null. To solve this issue I defined the cashtimeout property =200 but it stills makes the same issue. I don't know why I can't navigate between the pages.

Would you please help?


here is the code :

Code: Select all

public static StiReport WithReportFromXmlString(this StiReport report, string xmlStr)
        {
            using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(xmlStr)))
            {
                report.Load(stream);
            }
            return report;
        }
public static StiReport WithReportDatabaseConnection(this StiReport report, string connectionName, string databaseConnection)
        {
            //string before = report.ConvertReportDictionaryToXmlString();

            string connectionType = String.Empty;

            if (report.Dictionary.Databases.Count > 0)
            {
                connectionType = (((StiDatabaseCollection)report.Dictionary.Databases)[0]).GetType().Name;

                if (String.IsNullOrEmpty(connectionName))
                {
                    connectionName = (((StiDatabaseCollection)report.Dictionary.Databases)[0]).Name;
                }
            }

            switch (connectionType)
            {
                case "StiSqlDatabase":
                    report.Dictionary.Databases.Clear();
                    report.Dictionary.Databases.Add(new StiSqlDatabase(connectionName, databaseConnection));
                    foreach (StiSqlSource s in report.Dictionary.DataSources)
                        if (s.CommandTimeout <= 30)
                        {
                            s.CommandTimeout = 200;
                        }

                    break;

                case "StiOleDbDatabase":
                    report.Dictionary.Databases.Clear();
                    report.Dictionary.Databases.Add(new StiOleDbDatabase(connectionName, databaseConnection));
                    foreach (StiSqlSource s in report.Dictionary.DataSources)
                        if (s.CommandTimeout <= 30)
                        {
                            s.CommandTimeout = 200;
                        }
                    break;

                default:
                    report.Dictionary.Databases.Clear();
                    report.Dictionary.Databases.Add(new StiSqlDatabase(connectionName, databaseConnection));
                   foreach (StiSqlSource s in report.Dictionary.DataSources)
                        if (s.CommandTimeout <= 30)
                        {
                            s.CommandTimeout = 200;
                        }
                    break;
            }

            //string after = report.ConvertReportDictionaryToXmlString(); 

            return report;
        }


public static StiReport WithReportSchemaVariable(this StiReport report, string varName, string varValue)
        {
            if (report.Dictionary.Variables.Contains(varName))
                report.Dictionary.Variables.Remove(varName);

            report.Dictionary.Variables.Add(new StiVariable("Do Not Touch", varName, typeof(String), varValue, true));
            return report;
        }
public ActionResult GetReportSnapShot(Controller ctrl)
        {
            StiOptions.Export.Html.UseStrictTableCellSize = false;
            StiOptions.Export.Html.ForceWysiwygWordwrap = true;

            StiReport report = new StiReport();
            string ReportSource = String.Empty;

            if (null == _reportConfig || null == _reportConfig.ReportSource)
                return new HttpNotFoundResult();

            if (!String.IsNullOrEmpty(_reportConfig.ReportPath))
            {
                string path = ctrl.HttpContext.Server.MapPath(_reportConfig.ReportPath);
                report.Load(path);
                ReportSource = report.ConvertReportToXmlString();
            }
            else
            {
                ReportSource = _reportConfig.ReportSource;
            }


            string ReportConnectionValue = _reportConfig.ReportDataConnectionString; 
            string ReportSchemaName = _reportConfig.ReportSchemaName; // "dbo";

            report = new StiReport()
                .WithReportFromXmlString(ReportSource)
                .WithReportDatabaseConnection(ReportConnectionValue)
                .WithReportSchemaVariable(ReportSchemaName)
                .SetClientTimeZoneById(_reportConfig.TimeZone);

            if (_reportConfig.ReportParameters != null)
            {
                foreach (var reportParameter in _reportConfig.ReportParameters)
                {
                    report = report.WithReportVariable(reportParameter.ParameterName, reportParameter.ParameterValue); // .WithReportVariable("fBatchId", "'{A3CEDFBD-F880-4aa3-B314-E43B4615B242}'");
                }
            }

                     
            report.Dictionary.Synchronize();
            report.ReportCacheMode = StiReportCacheMode.On;
            StiOptions.Engine.ReportCache.AmountOfProcessedPagesForStartGCCollect = 2; // default - 20
            StiOptions.Engine.ReportCache.AmountOfQuickAccessPages = 5; // default - 50
            
            
            return StiMvcViewer.GetReportResult(report);
        }
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Cashing issue

Post by Alex K. »

Hello,

Please clarify which product and version are you use?

Thank you.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Cashing issue

Post by Alex K. »

Hello,

Also, please try to use the report.Render(false) method before showing report and let us know about the result.

Thank you.
Post Reply