Changing Database Type
Our sample projects and report templates can help you learn the basics of working with our products.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
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.