Page 1 of 1

Setting parameter in precompiled reports

Posted: Fri Feb 15, 2013 10:06 am
by simgschw
Hi,

I have a report which uses data from a database connection. The queries of the datasources need some parameters which are defined as report parameters. I programmactically generate thousands of reports each day. The difference of these reports are the parameter values.

Imagine, loading thousands of reports, setting the parameter values, compiling the reports, rendering the reports and saving them as pdf dokuments ... This workflow takes a lot of time and maybe this is a waste of time when using precompiled reports.

I tested report generation with precompiled reports with simple report templates. This worked, but when increasing the complexity of the report it didnt' work any more.


In my project I loading the report like this (from http://admin.stimulsoft.com/Documentati ... _asse3.htm):

Code: Select all

C#

 

string reportName = "MyReport.mrt";
string reportDllName = "MyReport.dll";
StiReport report = null;

// if report dll is not exists ...
if (!File.Exists(reportDllName))
{
   // load report definition
   report = new StiReport();
   report.Load(reportName);
   // compile report, save dll version of report
  report.Compile(reportDllName);
}
else // if report assembly is available …
{
    // … use it
   report = StiReport.GetReportFromAssembly(reportDllName);
}
To reproducing this bug/issue you can find a c# project in the attachments. This project is from your sample projects (SqlParameters). I did some changes in the code to reproduce my issue. You can find my changes in this method from Form1.cs:

Code: Select all

private void button1_Click(object sender, System.EventArgs e)
{
            string reportDllName = "Report.dll";
            stiReport1.Compile(reportDllName);
            //without next statement report generating works!
            stiReport1 = StiReport.GetReportFromAssembly(reportDllName);
            for (int i = 0; i < lbCountries.Items.Count; i++) {
                setParameter(lbCountries.Items[i].ToString());
                stiReport1.Render(false);
                Export(lbCountries.Items[i].ToString());
            }
}
As you can read in my comment, when I do not load the report from the assembly, generating the reports works, but takes in my case too long. Loading the report from the assembly is rather fast, but doesn't work.


I hope I stated my issue/problem clear enough. In any case take a look at the c# project in the attachment.


Thx in advance, greetings

Re: Setting parameter in precompiled reports

Posted: Fri Feb 15, 2013 1:19 pm
by Alex K.
Hello,

Please try to use the additional variable. Set this variable in parameter expression in datasource. And in code set the value for this variable.

Thank you.

Re: Setting parameter in precompiled reports

Posted: Mon Feb 18, 2013 8:45 am
by simgschw
Hi,

as you suggested I added a new dictionary variable. The value of the variable is set to the parameter's value of the datasource.

Project compiled and had no errors. In debug mode, i stepped through the run and opened the designer view for each report and it worked. but saving the generated reports to pdf or open them in the viewer didn't work.

Can you tell me what is wrong in my project?

Thx. greetings

Re: Setting parameter in precompiled reports

Posted: Tue Feb 19, 2013 8:09 am
by HighAley
Hello.

If you use compiled report, all data sources are compiled to classes. So you could change the variable value in the compiled report with next code:

Code: Select all

report.CompiledReport["countryID"] = country;
Let us know if you will have any problem in the implementation.

Thank you.

Re: Setting parameter in precompiled reports

Posted: Tue Feb 19, 2013 12:11 pm
by simgschw
Tried this solution and it works. But using the precompiled report with

Code: Select all

stiReport1 = StiReport.GetReportFromAssembly(reportDllName);
and setting the SQL-parameter with

Code: Select all

stiReport1[varName] = country
it does not work anymore.

Can you tell me how to set a parameter in a report that is loaded from assembly? What I mean by this, is that not only the setting is important but also that the report ist saved in the files correctly!

Please have a look at the adapted attachment!


Thx, greetings

Re: Setting parameter in precompiled reports

Posted: Wed Feb 20, 2013 11:05 am
by Alex K.
Hello,

In this case please try to use the following code:

Code: Select all

stiReport1.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiOleDbDatabase("NorthWind", "NorthWind", "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=" + path + "\\Data\\Nwind.mdb", false));
instead

Code: Select all

//stiReport1.RegData("NorthWind", connection);
In this case you can set the parameter value withou the additioanl variable.

Code: Select all

stiReport1["@countryID"] = country;
Thank you.