Database connection on server side
Database connection on server side
Is it mandatory to use the mySQL or MSSQL adapters when trying to connect to a database on the server side (e.g. Node.js) ? Or is there another way to make the connection to the database on the server side ?
Re: Database connection on server side
Hello Joanne,
Please try to add the following line of code in the first place. This method initializes the data adapters for Node.js
Stimulsoft.System.NodeJs.initialize();
Please let us know about the result.
Thank you.
Please try to add the following line of code in the first place. This method initializes the data adapters for Node.js
Stimulsoft.System.NodeJs.initialize();
Please let us know about the result.
Thank you.
Re: Database connection on server side
Hi, thanks for the reply. Do you have a full example of database connection and node.js + creating the report ?
What I am trying to achieve is the following:
- create a report template in the designer (with no database connection or data source attached - just the formatting, for e.g. columns layout for a simple list)
- then on node.js, create the database connection and data source, set it to the report template loaded and create the report (either saved on disk or returned as JSON string to the client side to be displayed in the viewer)
Is this possible ? I have not been able to achieve this, the result is always a blank report with the error "Cannot read property 'getType' of null" in the console log.
NOTE: I'm using the latest build - 2015.3
Thanks
What I am trying to achieve is the following:
- create a report template in the designer (with no database connection or data source attached - just the formatting, for e.g. columns layout for a simple list)
- then on node.js, create the database connection and data source, set it to the report template loaded and create the report (either saved on disk or returned as JSON string to the client side to be displayed in the viewer)
Is this possible ? I have not been able to achieve this, the result is always a blank report with the error "Cannot read property 'getType' of null" in the console log.
NOTE: I'm using the latest build - 2015.3
Thanks
Re: Database connection on server side
Hi, do you have guidelines for server side report creation and for database & datasource creation and linking to the report ?
I am desperately trying to make a simple report with a connection to a MySQL database work, but without any luck (using latest build 2015.3), if we go for Stimulsoft reports, it is very important for us to be able to set the connection information in the code itself.
When creating the report in designer with a MySQL connection and data source, it works well in the preview; the data is displayed. But when using same report and rendering on node.js server, nothing.... A blank report is returned and when looking at the ".mdc" file created, the database and data source information is not there....
The only error message displayed is "Cannot read property 'getType' of null" on the server console log.
I have attached the template file "empList.mrt" to this reply.
Please help.
Thanks
Below is my code on node.js server which returns the rendered report string to be viewed on client side in HTML viewer:
I am desperately trying to make a simple report with a connection to a MySQL database work, but without any luck (using latest build 2015.3), if we go for Stimulsoft reports, it is very important for us to be able to set the connection information in the code itself.
When creating the report in designer with a MySQL connection and data source, it works well in the preview; the data is displayed. But when using same report and rendering on node.js server, nothing.... A blank report is returned and when looking at the ".mdc" file created, the database and data source information is not there....
The only error message displayed is "Cannot read property 'getType' of null" on the server console log.
I have attached the template file "empList.mrt" to this reply.
Please help.
Thanks
Below is my code on node.js server which returns the rendered report string to be viewed on client side in HTML viewer:
Code: Select all
var connStr,
ds,
report,
reportTemplate,
renderedReport;
// added the following line based on response from support team - but does not seem to work...
Stimulsoft.System.NodeJs.initialize();
// 1. create report object
report = new Stimulsoft.Report.StiReport();
console.log('report created');
// 2. load template
reportTemplate = fs.readFileSync('./reportTemplates/empList.mrt', "utf8");
report.load(reportTemplate);
console.log('report loaded');
console.log('pages: ' + report.pages.count);
// 3. change connection string
// -- 3.1 set connection string
report.dictionary.databases.clear();
connStr = "UserID=root;Password=1234;Host=localhost;Port=3306;Database=testdb";
report.dictionary.databases.add(new Stimulsoft.Report.Dictionary.StiMySqlDatabase("TestJS", "TestJS", connStr));
// added the following line based on Report.JS programming manual (Synchronize Data between DataStore and Dictionary) section
report.dictionary.synchronize();
// -- 3.2 create data source
ds = new Stimulsoft.Report.Dictionary.StiDataSource('shrm_employee', 'shrm_employee', 'shrm_employee');
ds.columns.add(new Stimulsoft.Report.Dictionary.StiDataColumn("employeeCode", "employeeCode", "employeeCode"));
ds.columns.add(new Stimulsoft.Report.Dictionary.StiDataColumn("employeeName", "employeeName", "employeeName"));
ds.columns.add(new Stimulsoft.Report.Dictionary.StiDataColumn("employeeSurname", "employeeSurname", "employeeSurname"));
ds.sqlCommand = "SELECT * FROM shrm_employee WHERE scopeId = 2000;";
report.dictionary.dataSources.add(ds);
report.regData();
report.renderAsync(function () {
console.log('report rendered. pages: ' + report.renderedPages.count);
renderedReport = report.saveDocumentToJsonString();
fs.writeFileSync('./reportTemplates/empList.mdc', renderedReport);
res.send({statusCode:200, message: "Report Created", reportData: renderedReport});
});
- Attachments
-
- empList.mrt
- Test template file
- (3.4 KiB) Downloaded 316 times
Re: Database connection on server side
Hello,
but the regData method has 3 parameters:
Also, the regData method is used for direct data transfer (dataTable, dataSet, xml, json, etc).
But in your case the database is used, so calling this method is not needed.
Thank you.
From your code:The only error message displayed is "Cannot read property 'getType' of null" on the server console log.
Code: Select all
report.regData();
Code: Select all
public regData(name: string, alias: string, data: any)
But in your case the database is used, so calling this method is not needed.
Thank you.
Re: Database connection on server side
Hi, thanks for the reply. I have been able to set the database and data source connection on server side (node.js). Attached is the report template used for this example. The final code looks like below:
Code: Select all
var fs = require('fs'),
Stimulsoft = require('stimulsoft-reports-js').Stimulsoft,
connStr,
ds, sqlQuery,
report,
reportTemplate,
renderedReport,
repPage, dtBand, dataText;
// 1. create report object
report = new Stimulsoft.Report.StiReport();
console.log('report created');
// 2. load template
reportTemplate = fs.readFileSync('./empList.mrt', "utf8");
report.load(reportTemplate);
console.log('report loaded');
console.log('pages: ' + report.pages.count);
// 3. change connection string
// -- 3.1 set connection string
report.dictionary.databases.clear();
connStr = "UserID=root;Password=123456;Host=localhost;Port=3306;Database=testdb";
report.dictionary.databases.add(new Stimulsoft.Report.Dictionary.StiMySqlDatabase("LocalJS", "LocalJS", connStr));
// -- 3.2 create data source
sqlQuery = 'SELECT * FROM tb_employee';
// StiMySqlSource(string nameInSource, string name, string alias, string sqlCommand, bool connectOnStart, bool reconnectOnEachRow, int commandTimeout, string key)
ds = new Stimulsoft.Report.Dictionary.StiMySqlSource("LocalJS", 'tb_employee', 'tb_employee', sqlQuery, true);
ds.columns.add(new Stimulsoft.Report.Dictionary.StiDataColumn("employeeCode", "employeeCode", "employeeCode"));
ds.columns.add(new Stimulsoft.Report.Dictionary.StiDataColumn("employeeName", "employeeName", "employeeName"));
ds.columns.add(new Stimulsoft.Report.Dictionary.StiDataColumn("employeeSurname", "employeeSurname", "employeeSurname"));
report.dictionary.dataSources.add(ds);
// reset data band's data source
repPage = report.pages.getByName('Page1');
dtBand = repPage.components.getByName('db_employees');
dtBand.dataSourceName = 'tb_employee';
// reset text on data band
// -- emp. code
dataText = dtBand.components.getByName('txt_empCode');
dataText.text = "{tb_employee.employeeCode}";
// -- emp. Name
dataText = dtBand.components.getByName('txt_empName');
dataText.text = "{tb_employee.employeeName}";
// -- emp. surname
dataText = dtBand.components.getByName('txt_empSurname');
dataText.text = "{tb_employee.employeeSurname}";
report.dictionary.synchronize();
report.renderAsync(function () {
console.log('report rendered. pages: ' + report.renderedPages.count);
renderedReport = report.saveDocumentToJsonString();
// save as document file on server
fs.writeFileSync('./empList.mdc', renderedReport);
// return as JSON string which can be used in the HTML viewer on client side
res.send({statusCode:200, message: "Report Created", reportData: renderedReport});
});
- Attachments
-
- empList.mrt
- (3.74 KiB) Downloaded 332 times
Re: Database connection on server side
Hello.
We have made an improvement.
Please, try our next prerelease build on December 11.
Thank you.
We have made an improvement.
Please, try our next prerelease build on December 11.
Thank you.
Re: Database connection on server side
Hi HighAley, thanks for the reply. What improvement has been made concerning the data base connection on server side ?
Re: Database connection on server side
Hello.
There was no changes on server-side. We have made an improvement on client side.
Thank you.
There was no changes on server-side. We have made an improvement on client side.
Thank you.