I am saving Stimulsoft report in database and then loading it from database. I am using stored procedure as datasource and only showing stored procedures that starts with "rpt_" as there are number of stored proc in my db.
Now, below is the code for designer, where I assign stored proc to report. However, I don't assign the datasource that already exist as if I don't remove existing ones it shows duplicates of stored procedures in report designer datasource.
Code: Select all
private void OnDesignerAfterRender()
{
var sqlDatabase = new StiSqlDatabase("Database", DatabaseConnection.ConnectionString);
var dbInfo = sqlDatabase.GetDatabaseInformation(this.Report);
dbInfo.Tables.Clear();
dbInfo.Views.Clear();
dbInfo.Relations.Clear();
dbInfo.StoredProcedures.RemoveAll(x => !x.TableName.StartsWith("rpt_"));
List<string> storedProcNames = new();
foreach (var db in dbInfo.StoredProcedures)
{
if (this.Report.DataSources.Contains(db.TableName))
{
storedProcNames.Add(db.TableName);
}
}
dbInfo.StoredProcedures.RemoveAll(x => storedProcNames.Contains(x.TableName));
sqlDatabase.ApplyDatabaseInformation(dbInfo, this.Report);
this.Report.Dictionary.Databases.Add(sqlDatabase);
JSRuntime.InvokeVoidAsync("createButton");
}
Problem is that if I update stored procedure (add column/remove column) the datasource don't show that in designer since I am not updating datasource of report.
If I overwrite the report datasource means clear report datasource and then apply. The report stops working and doesn't generate any data.
Code: Select all
private void OnDesignerAfterRender()
{
var sqlDatabase = new StiSqlDatabase("Database", DatabaseConnection.ConnectionString);
var dbInfo = sqlDatabase.GetDatabaseInformation(this.Report);
dbInfo.Tables.Clear();
dbInfo.Views.Clear();
dbInfo.Relations.Clear();
dbInfo.StoredProcedures.RemoveAll(x => !x.TableName.StartsWith("rpt_"));
//Clear before applying
this.Report.DataSources.Clear();
sqlDatabase.ApplyDatabaseInformation(dbInfo, this.Report);
this.Report.Dictionary.Databases.Add(sqlDatabase);
JSRuntime.InvokeVoidAsync("createButton");
}