Trying to re-use the same report... bad results

Stimulsoft Reports.NET discussion
Post Reply
a.marinelli
Posts: 17
Joined: Wed Nov 14, 2012 1:39 pm

Trying to re-use the same report... bad results

Post by a.marinelli »

I have one report that should launched many times changing just one parameter, and I'm trying to NOT recompile each time the MRT (to save memory).

1. The first time the report has been requested I load in a private variable:

Code: Select all

                    string reportToLaunch = Path.Combine(@"c:\path", "report.mrt");

                    _CostificationMOReport = new StiReport();
                    _CostificationMOReport.Load(reportToLaunch);
                    _CostificationMOReport.Compile();
2. after the Compile() I inject the Datasource parameter:

Code: Select all


_CostificationMOReport.DataSources["MyDS"].Parameters.Clear();
_CostificationMOReport.CompiledReport.DataSources["MyDS"].Parameters.Clear();

_CostificationMOReport.DataSources["MyDS"].Parameters.Add(new Stimulsoft.Report.Dictionary.StiDataParameter("@pID", "1", 22, 50));
_CostificationMOReport.CompiledReport.DataSources["MyDS"].Parameters.Add(new Stimulsoft.Report.Dictionary.StiDataParameter("@pID", "1", 22, 50));

3. finally I render it and assign to report viewer

Code: Select all


_CostificationMOReport.Render(false);

_viewer.Report = _CostificationMOReport;

When my code call the same report I'm trying to avoid re-compiling the MRT doing the following:

Code: Select all


//clear pages
_viewer.Report =null;
_CostificationMOReport.CompiledReport.RenderedPages.Clear();

//clear old parameters
_CostificationMOReport.DataSources["MyDS"].Parameters.Clear();
_CostificationMOReport.CompiledReport.DataSources["MyDS"].Parameters.Clear();

//inject new parameters
_CostificationMOReport.DataSources["MyDS"].Parameters.Add(new Stimulsoft.Report.Dictionary.StiDataParameter("@pID", "2", 22, 50));
_CostificationMOReport.CompiledReport.DataSources["MyDS"].Parameters.Add(new Stimulsoft.Report.Dictionary.StiDataParameter("@pID", "2", 22, 50));

//render
_CostificationMOReport.Render(false);

//re-assign to report viewer
_viewer.Report = _CostificationMOReport;

//I tried even this, but doesn't work
// _CostificationMOReport.ViewerControl = _viewer;
// _CostificationMOReport.Show();
// _CostiticationMOReport.InvokeRefreshViewer();

but the report always shows the old values... how to manage this?

If this is the wrong way, how can I re-use the same report without re-compiling it each time (avoiding memory leaks and improving performance)?

thanks in advance

[Stimulsoft Reports .NET 2012.2]
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Trying to re-use the same report... bad results

Post by HighAley »

Hello.

You could do it more easier. You don't need to Clear parameters. Here is a sample code:

Code: Select all

StiReport rep = new StiReport();
rep.Load("Report.mrt");
rep.Compile();
rep["Par1"] = 5;
rep.Render();
rep.Show(true);
rep["Par1"] = 7;
rep.Render();
rep.Show(true);
Thank you.
Attachments
Report.mrt
(4.25 KiB) Downloaded 151 times
a.marinelli
Posts: 17
Joined: Wed Nov 14, 2012 1:39 pm

Re: Trying to re-use the same report... bad results

Post by a.marinelli »

thanks for your reply, your code works perfectly, but it seems not work with my report.

I'm trying to "refresh" the parameters in many ways, but none of these worked:

Code: Select all


//re-inject all query parameters
            foreach (ReportQueryParameter p in _currentQueryParameters)
            {
                        report[p.ParameterName]= "" + p.ParameterValue;
                        report.DataSources[p.DataSourceName].Parameters.Add(new Stimulsoft.Report.Dictionary.StiDataParameter(p.ParameterName, "" + p.ParameterValue, 22, 50));
                        report.Dictionary.DataSources[p.DataSourceName].Parameters[p.ParameterName].Value = "" + p.ParameterValue;
                        report.Dictionary.DataSources[p.DataSourceName].Parameters[p.ParameterName].ParameterValue = "" + p.ParameterValue;
                        report.CompiledReport.DataSources[p.DataSourceName].Parameters.Add(new Stimulsoft.Report.Dictionary.StiDataParameter(p.ParameterName, "" + p.ParameterValue, 22, 50));
                    
                }
            }
only the first injected set of parameters is used, just like they was "cached"...

any other hints?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Trying to re-use the same report... bad results

Post by HighAley »

Hello.

We will only guess what issue do you have until we see a sample project with a report template and sample data which reproduces your issue.
Could you send it to us?

Thank you.
a.marinelli
Posts: 17
Joined: Wed Nov 14, 2012 1:39 pm

Re: Trying to re-use the same report... bad results

Post by a.marinelli »

i found the problem: we are using the Form Load event to "manipulate" the given parameters and to set them to various datasources, but this event fires only once (at the first compile), so internally the parameters never refresh.

moved our code to Report BeginRender event and it seems to work, but it is very slow (probably because it's fired many times)... any hints?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Trying to re-use the same report... bad results

Post by HighAley »

Hello.

Here is a sample code for this before compilation:

Code: Select all

StiReport report = new StiReport();
report.Load("d:\\stimulsoft\\1\\ReportArguments2.mrt");
report.Dictionary.Variables["Variable1"].Value = yourCancatenatedString;
report.Compile();
report.Render(false);
report.Show();
or after compilation:

Code: Select all

report.Compile();
report["Variable1"] = yourCancatenatedString;
report.Render(false);
report.Show();
Thank you.
a.marinelli
Posts: 17
Joined: Wed Nov 14, 2012 1:39 pm

Re: Trying to re-use the same report... bad results

Post by a.marinelli »

it's ok, now it's working, thank you, but it's very very slow... if I activate CacheMode or CacheAllData parameters on report will I experience the same refresh problems?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Trying to re-use the same report... bad results

Post by HighAley »

Hello.
a.marinelli wrote:it's ok, now it's working, thank you, but it's very very slow... if I activate CacheMode or CacheAllData parameters on report will I experience the same refresh problems?
Could you describe this issue more detailed. If it possible with examples.

Thank you.
a.marinelli
Posts: 17
Joined: Wed Nov 14, 2012 1:39 pm

Re: Trying to re-use the same report... bad results

Post by a.marinelli »

1. I pre-compile the report when loading my form
2. basing on a treeview control, I inject parameters in the report at runtime, I render it and show it a StiViewer [my original problem is SOLVED]
3. when rendering the report is very slow

My new question is: if I enable CacheMode/CacheAllData in the report could I invalidate the point 2 (and re-broke my app)?
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Trying to re-use the same report... bad results

Post by Alex K. »

Hello,

Can you please clarify which version do you use.
Also please send us your report for analysis.

Thank you.
Post Reply