Page 1 of 1

Preview in mobile designer with StiSqlSource data source?

Posted: Thu Aug 20, 2015 9:16 pm
by agent005
Hello,

I'm wondering if it's possible to get a preview working in mobile designer when report uses a few StiSqlSource data sources?
I've checked a demo project but it's using DataTableSource and not database queries.

Is it possible to build a DataSet on the server and provide it for the report (this does not seem to work though as I get a blank report on preview).
Please advise. Maybe you have a sample code on how to get preview working for database-driven reports?

Code: Select all

    protected void StiMobileDesigner1_GetDataSetOnLoad(object sender, Stimulsoft.Report.MobileDesign.StiMobileDesigner.StiLoadReportEventArgs e)
    {
        DataSet data = new DataSet();
        SqlConnection sqlConnection = new SqlConnection(ConnectionString);
        sqlConnection.Open();

        foreach (var ds in e.Report.DataSources.ToList())
        {
            string sql = ((StiSqlSource)ds).SqlCommand;

            SqlCommand cmdSP = new SqlCommand();
            cmdSP.CommandText = sql;
            cmdSP.CommandType = CommandType.Text;
            cmdSP.Connection = sqlConnection;
            SqlDataAdapter da = new SqlDataAdapter(cmdSP);
            DataSet dataSet = new DataSet();
            da.Fill(dataSet, 0, 0, "default");

            DataTable dt = dataSet.Tables[0].Copy();
 
            dt.TableName = ds.Name;
            data.Tables.Add(dt);
        }
        e.Report.RegData(data);
        e.Report.Dictionary.Synchronize();
    }

Re: Preview in mobile designer with StiSqlSource data source

Posted: Fri Aug 21, 2015 7:01 am
by HighAley
Hello.

Could you specify what version of our product you use?
The GetDataSetOnLoad event is obsolete now.
If you register data from DataSet you should use Preview event to register data for preview.
You could create a SQL connection in the report then it will be not necessary to register DataSet again.

Thank you.

Re: Preview in mobile designer with StiSqlSource data source

Posted: Fri Aug 21, 2015 1:58 pm
by agent005
I'm using Ultimate 2015.1 version.
So what exactly do I do in the Preview event? Should I just put correct connection string in the report and then it will render correctly?
Any examples would be really helpful.

Re: Preview in mobile designer with StiSqlSource data source

Posted: Sat Aug 22, 2015 5:40 am
by Jan
Hello,

Ok. Thank you for additional information.

Stimulsoft Reports can handle information in two ways:
1. Direct access from report;
2. Register it from app.

1. If you specify connection directly in report you don't need change something in report before report rendering. Report engine automatically create connection and retrieve data. Usually our customers only change connection string in report before rendering. So in design-time you can use temp connection string, in run-time you use real-life connection string. Here is a code for changing connection string in report connection before report rendering:

Code: Select all

var report = new StiReport();
report.LoadFromString(strReport);
var database = report.Dictionary.Databases["MyConnection"] as StiSqlDatabase;
database.ConnectionString = "new connection string";
You should do this only before real-life rendering, not in Preview event. Because in last case you will tranfer new connection string to report in report designer.

2. If you transfer data to report from your app (with help of RegData method) you should use Preview event of report designer. Why you need use this event. Because data which registered with help of RegData method of report is not stored on server-side you need register it before report rendering in preview tab of report designer.

Let me known if you have additional question.

Thank you.

Re: Preview in mobile designer with StiSqlSource data source

Posted: Tue Aug 25, 2015 7:54 pm
by agent005
Yes, I do replace connection string like you show above before rendering a report.

OK, so I have a report with data being directly accessed from the report (through sql connection).

Is it possible to make my report work with Preview option? (ideally without sending production connection string to report designer)

Re: Preview in mobile designer with StiSqlSource data source

Posted: Wed Aug 26, 2015 10:39 am
by HighAley
Hello.

You could register some dataset in report and design it.
After this you should remove the Data Sources from dataset and add SQL connection and Data Sources with the same name.
Let us know if you need any additional help to do this.

Thank you.

Re: Preview in mobile designer with StiSqlSource data source

Posted: Wed Aug 26, 2015 4:24 pm
by agent005
Well, I already have the report designed, and just want to give users an option to do some minor tweaks to it, so it's not very practical to remove existing sql data sources, replace with DataTableSources, provide data, and then replace those back to sql data sources...

It would be much easier if in Preview event I could provide a correct sql connection (and some parameters if needed), report would get rendered and shown in preview. Can you add this feature to be considered for future releases?

Re: Preview in mobile designer with StiSqlSource data source

Posted: Thu Aug 27, 2015 7:36 am
by HighAley
Hello.

You could set working connection for the report before passing it to Designer.
If you don't want to show connection string. It's possible to hide it. You could use the PermissionDataConnections property of the Mobile Designer.

Thank you.