How to enumerate the variables contained in an MRT file

Stimulsoft Reports.WEB discussion
kgb2013
Posts: 85
Joined: Fri Nov 01, 2013 9:52 am
Location: Earth

How to enumerate the variables contained in an MRT file

Post by kgb2013 »

Hello.

I need to retrieve the variables (and their type) used in an MRT file.
Is there a standard way of doing this through your library or I will have to parse the MRT XML myself?
I see that the :

Code: Select all

StiReport.Variables
is only for the code-defined variables.

Thanks. :)
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: How to enumerate the variables contained in an MRT file

Post by HighAley »

Hello.

You could find all variables here:

Code: Select all

StiReport.Dictionary.Variables
Thank you.
kgb2013
Posts: 85
Joined: Fri Nov 01, 2013 9:52 am
Location: Earth

Re: How to enumerate the variables contained in an MRT file

Post by kgb2013 »

For some reason, even

Code: Select all

StiReport.Dictionary.Variables
...is empty.

Please check if I do anything wrong (see attached image):

I need to have MRT files with SQL queries that accept parameters in their code.
So, I have written some SQL queries with variables contained in them (like "SELECT * FROM STH WHERE Id=@IdParam").
Next, I have added the parameter "IdParam" and set it's expression to "IdParam" trying to get the value of a (user provided) variable (which is defined in the variables of the MRT report).
I have checked the option "Request From User" for this variable. (However I have some variables that don't have this set because I need to fill them by code - I don't know if this matters.)
Next, I set in my code the report property to make the UI show the parmeter's input area:

Code: Select all

StiReport report = ...;
report.RequestParameters = true;
However, this doesn't show the parameter input area and my StiReport.Dictionary.Variables is empty. :(

Am I missing something?

Thanks.
Attachments
Stim3.PNG
Stim3.PNG (42.43 KiB) Viewed 4393 times
Stim.PNG
Stim.PNG (103.18 KiB) Viewed 4393 times
kgb2013
Posts: 85
Joined: Fri Nov 01, 2013 9:52 am
Location: Earth

Re: How to enumerate the variables contained in an MRT file

Post by kgb2013 »

I see that in your demo:
Stimulsoft Reports.Web 2013.2 Trial\Samples\ASP.NET MVC\MvcViewer (Razor)\MvcViewer (Razor)
..you use a StiReport-derived class for the report that supports input of parameters.
Is this nessesary? What is this file (ParametersSelectingCountry.cs) doing? It looks like auto-generated.

If I just do this:

Code: Select all

		StiReport GetReport()
		{
				var report = new StiReport();
				SetReportParameters(report);
				report.Load(mrtFilePath);
		}

		public ActionResult GetReportSnapshot(ListModel model)
		{
			using(var report = GetReport(model))
			{
				return StiMvcViewer.GetReportSnapshotResult(HttpContext, report);
			}
		}
..won't the parameters area appear when there are parameters defined in the MRT ?
kgb2013
Posts: 85
Joined: Fri Nov 01, 2013 9:52 am
Location: Earth

Re: How to enumerate the variables contained in an MRT file

Post by kgb2013 »

By the way, I do see the variables in :

Code: Select all

StiReport.Dictionary.Variables
I was doing sth wrong before.
Silly me...

But the varaible declaration area in the viewer insists on not showing up. :(
Instead, it tries to execute the query without the parameters being provided and it generates an error.
Vladimir
Posts: 1462
Joined: Fri Apr 13, 2007 4:05 am
Location: Earth

Re: How to enumerate the variables contained in an MRT file

Post by Vladimir »

Hello,

For correct work with the variables in MvcViewer, you need to identify ActionInteraction. For details, please see the example below:

http://www.stimulsoft.com/en/documentat ... meters.htm

Thank you.
kgb2013
Posts: 85
Joined: Fri Nov 01, 2013 9:52 am
Location: Earth

Re: How to enumerate the variables contained in an MRT file

Post by kgb2013 »

Thanks.

I have added these:

Code: Select all

		new StiMvcViewerOptions()
		{
			...
			ActionInteraction = "Interaction",
		...


		public ActionResult Interaction()
		{
			using (var report = GetReport())
			{
				return StiMvcViewer.InteractionResult(this.HttpContext, report);
			}
		}
Now, I see the parameters area, but only after an error (it calls "ActionGetReportSnapshot" before showing the parameters area - perhaps this http://forum.stimulsoft.com/viewtopic.p ... 84&p=68702 can help me on that).

And when I submit the parameters, again it throws this exception:
The parameterized query '............................' expects the parameter '@ToDate', which was not supplied.

at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at Stimulsoft.Report.Dictionary.StiSqlSource.UpdateParameters()
at Stimulsoft.Report.Dictionary.StiSqlAdapterService.ConnectDataSourceToData(StiDictionary dictionary, StiDataSource dataSource, Boolean loadData)
at Stimulsoft.Report.Dictionary.StiDataSource.Connect(StiDataCollection datas, Boolean loadData)
at Stimulsoft.Report.Dictionary.StiDataSourcesCollection.Connect(StiDataCollection datas, Boolean loadData)
at Stimulsoft.Report.Dictionary.StiDataSourcesCollection.Connect(Boolean loadData)
at Stimulsoft.Report.Dictionary.StiDictionary.Connect(Boolean loadData)
at Stimulsoft.Report.Dictionary.StiDictionary.Connect()
at Stimulsoft.Report.Engine.StiRenderProviderV2.ConnectToData(StiReport report)
at Stimulsoft.Report.Engine.StiRenderProviderV2.Render(StiReport report, StiRenderState state)
at Stimulsoft.Report.Engine.StiReportV2Builder.RenderSingleReport(StiReport masterReport, StiRenderState renderState)
at Stimulsoft.Report.StiReport.RenderReport(StiRenderState renderState)
at Stimulsoft.Report.StiReport.Render(StiRenderState renderState, StiGuiMode guiMode)
at Stimulsoft.Report.StiReport.Render(StiRenderState renderState)
at Stimulsoft.Report.StiReport.Render(Boolean showProgress, Int32 fromPage, Int32 toPage)
at Stimulsoft.Report.StiReport.Render(Boolean showProgress)
at Stimulsoft.Report.Mvc.StiMvcViewer.SaveReportObject(HttpContextBase httpContext, StiReport report)
at Stimulsoft.Report.Mvc.StiMvcViewer.InteractionResult(HttpContextBase httpContext, StiReport report)
The "ToDate" parameter is in the parameters area and it is filled-in when I press the submit! :?
Vladimir
Posts: 1462
Joined: Fri Apr 13, 2007 4:05 am
Location: Earth

Re: How to enumerate the variables contained in an MRT file

Post by Vladimir »

Hello,

Please try to set the RequestParameters property of the report to True.
This should help in this situation.

Thank you.
kgb2013
Posts: 85
Joined: Fri Nov 01, 2013 9:52 am
Location: Earth

Re: How to enumerate the variables contained in an MRT file

Post by kgb2013 »

Yes, I have this set in the MRT file and I also do it in code:

Code: Select all

StiReport report = new StiReport();
report.Load(mrtFile);
report.RequestParameters = true;
Now I have also tried these:

Code: Select all

report.Dictionary.DataSources["MyDataSource"].Parameters[key].Value = (string)dic[key];
report.Dictionary.Variables[key].Value = (string)dic[key];
.and they don't seem to help.

Is the way I setup the MRT file in the screenshots above correct?
kgb2013
Posts: 85
Joined: Fri Nov 01, 2013 9:52 am
Location: Earth

Re: How to enumerate the variables contained in an MRT file

Post by kgb2013 »

I have found that I was doing sth wrong in one place.
Now I will try again.

EDIT:

I just added a:

Code: Select all

report.Dictionary.Variables["usrID"].Value = ident.UserId.ToString(CultureInfo.InvariantCulture);
...for the variables that are not requested by the user and now it works.

It seems that for some reason:

Code: Select all

report["usrID"] = ident.UserId;
..wasn't enough.
Post Reply