The connection string and SQL query of a report can be changed dynamically from code. This example swaps both when the report requests its data.

Preparing the data. Read or create the data source, register it in the report dictionary, synchronize the schema, and render with the supplied records.
import { Viewer, Stimulsoft } from 'stimulsoft-reports-js-react/viewer';

function App() {
    Stimulsoft.StiOptions.WebServer.url = 'http://localhost:9615/';

    var report = new Stimulsoft.Report.StiReport();
    report.loadFile('Reports/SimpleListSQL.mrt');

    report.onBeginProcessData = function (args) {
        // In this event, it is possible to handle the data request, and replace the connection parameters
        // You can change the connection string
        // This example uses the 'Northwind' SQL database, it is located in the 'Data' folder
        // You need to import it and correct the connection string to your database

        if (args.connection === 'MySQL')
            args.connectionString = 'Server=localhost; Database=northwind; UserId=root; Pwd=;';

        // You can change the SQL query
        if (args.dataSource === 'customers') args.queryString = 'SELECT * FROM MyTable';
    };

    return <Viewer report={report} />;
}

export default App;

The onBeginProcessData event exposes args.connectionString and args.queryString; replacing them per connection or data source lets one template target different databases. Requests are proxied through StiOptions.WebServer.url.

By using this website, you agree to the use of cookies for analytics and personalized content. Cookies store useful information on your computer to help us improve efficiency and usability. For more information, please read the privacy policy and cookie policy.