Not able to update data source linked to report

Stimulsoft Reports.BLAZOR discussion
Post Reply
muhammadhunainnasir
Posts: 25
Joined: Wed Mar 12, 2025 9:44 pm

Not able to update data source linked to report

Post by muhammadhunainnasir »

Hi,

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");
}
Max Shamanov
Posts: 990
Joined: Tue Sep 07, 2021 10:11 am

Re: Not able to update data source linked to report

Post by Max Shamanov »

Hello,

Please try to use the following code:

Code: Select all

report.Dictionary.Synchronize();
Also, please check our Blazor samples:
https://github.com/stimulsoft/Samples-R ... zor-Server

Thank you.
Post Reply