Preview in mobile designer with StiSqlSource data source?

Stimulsoft Reports.WEB discussion
Post Reply
agent005
Posts: 24
Joined: Mon Dec 22, 2014 3:05 pm

Preview in mobile designer with StiSqlSource data source?

Post 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();
    }
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Preview in mobile designer with StiSqlSource data source

Post 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.
agent005
Posts: 24
Joined: Mon Dec 22, 2014 3:05 pm

Re: Preview in mobile designer with StiSqlSource data source

Post 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.
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

Re: Preview in mobile designer with StiSqlSource data source

Post 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.
agent005
Posts: 24
Joined: Mon Dec 22, 2014 3:05 pm

Re: Preview in mobile designer with StiSqlSource data source

Post 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)
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Preview in mobile designer with StiSqlSource data source

Post 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.
agent005
Posts: 24
Joined: Mon Dec 22, 2014 3:05 pm

Re: Preview in mobile designer with StiSqlSource data source

Post 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?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Preview in mobile designer with StiSqlSource data source

Post 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.
Post Reply