Connect Report to MS SQL Server

Stimulsoft Reports.JS discussion
Post Reply
jonasrotilli
Posts: 12
Joined: Sat Mar 02, 2013 12:25 pm

Connect Report to MS SQL Server

Post by jonasrotilli »

I saw in the documentation that to connect to the sql server by Stimulsoft it is necessary to create an adapter, in my case Node. (an example exists in the gitub of the Stimulsoft path: https://github.com/stimulsoft/Samples-J ... p%20Server )

1 - I changed the adapter and I can connect to the SQL database, that is, when I enter the page http://localhost:9615... I get "success".

2 - In the html before invoking the stimulsoft I put according to the documentation explains: StiOptions.WebServer.url = 'http://localhost:9615/';

3 - The question is: how should I do in the designer of the report? What do I put in the DataSource options?
Will the query be inserted into the designer or should I inform the html, before uploading Stimulsoft?
SelectTipeOfConnection.png
SelectTipeOfConnection.png (59.93 KiB) Viewed 3068 times
Lech Kulikowski
Posts: 6259
Joined: Tue Mar 20, 2018 5:34 am

Re: Connect Report to MS SQL Server

Post by Lech Kulikowski »

Hello,

You can add all necessary object directly in the report - tables, views, procedures or your custom queries.
Also, you can prepare all data in your code and then provide it to the report as DataSet with RegData() method.

Thank you.
jonasrotilli
Posts: 12
Joined: Sat Mar 02, 2013 12:25 pm

Re: Connect Report to MS SQL Server

Post by jonasrotilli »

Do you mean that I should then choose the "SQL Server" option in the designer, and even put in the RegData() method in JavaScript before calling the report?
Give me an example of this RegData() that works, because with dataSet.readJsonFile("http://localhost:9615") has already tried and does not load the data.

It would be very interesting if there were practical and complete examples of the subject, in the documentation and in the samples everything is very fragmented.
jonasrotilli
Posts: 12
Joined: Sat Mar 02, 2013 12:25 pm

Re: Connect Report to MS SQL Server

Post by jonasrotilli »

After many attempts I succeeded!
For those who go through the same difficulty I did like this:

1 - Make a Node server that returns your queries in Json format. It should be working when you access the path of your node, for example, when typing in the browser http: // localhost: 1516 / api / articles (which is the address of my node server) will return Json.

2 - Get this json returned and save it on your PC and in the report designer add it. This way you will have all the structure of the table you want.

3 - Now before calling configure in JS:
report.loadFile ("/ views / Stimulsoft / reports / Report15.mrt");
var dataSet = new Stimulsoft.System.Data.DataSet ("root2");
dataSet.readJsonFile ("http: // localhost: 1516 / api / articles");
report.regData ("root", "root", dataSet);

viewer.report = report;

Ready! Each time you call the report it will not use Json placed in the designer, it will use the json generated by the node (generated by the path http: // localhost: 1516 / api / articles).

To do the Node the documentation of the stimulsoft suggests an adapter written by them, but that in my opinion only confuses. I use SQL Server from azure, so I made my own Node which generates a Json from a simple select. Attach here if anyone needs. Remember that to function and this node one should do an npm-install for "body-parser, express and mssql" to update / install a.

Tanks Lechs for your help!
Attachments
Node_API_Demo.zip
(1.18 MiB) Downloaded 216 times
Lech Kulikowski
Posts: 6259
Joined: Tue Mar 20, 2018 5:34 am

Re: Connect Report to MS SQL Server

Post by Lech Kulikowski »

Hello,

Thank you for the provided solution.
Post Reply