A report's data connection can be swapped for a different database type at run time without editing the template.

Changing the connection. Read the original database from the dictionary and convert it with ChangeDatabaseType, then set the new connection string:
public IActionResult GetReportWithChangedDatabase()
{
    var report = new StiReport();
    report.Load(StiNetCoreHelper.MapPath(this, "Reports/Report.mrt"));

    var originalJsonDatabase = (StiJsonDatabase)report.Dictionary.Databases[0];
    var newMySqlDatabase = (StiMySqlDatabase)report.Dictionary
        .ChangeDatabaseType(originalJsonDatabase, typeof(StiMySqlDatabase));
    newMySqlDatabase.ConnectionString =
        "Server=myServerAddress; Database=myDataBase; UserId=myUsername; Pwd=myPassword;";

    return StiNetCoreViewer.GetReportResult(this, report);
}
ChangeDatabaseType keeps the report's data structure (tables, columns, relations) but retargets it to a different provider, so one template can be served from JSON during development and from a production SQL database at run time.

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.