How to change the data source dynamically

To change the data source of a report dynamically in the Bold Reports® Angular Report Viewer, set reportOption.ReportModel.DataSourceCredentials in the OnInitReportOptions method of the Web API controller. The following code sample shows how to change the connection string of the <database> data source in the report.

    [NonAction]
    public void OnInitReportOptions(ReportViewerOptions reportOption)
    {
        DataSourceCredentials dataSourceCredentials = new DataSourceCredentials();

        string connectionString = "Data Source =<instancename> ; Initial Catalog = <database>; User ID = '<username>'; Password = '<password>'";

        //You have to provide the shared data source name used with the report or the data source name available with the report.
        dataSourceCredentials.Name = "<database>";
        dataSourceCredentials.ConnectionString = connectionString;
        reportOption.ReportModel.DataSourceCredentials = new List<DataSourceCredentials> { dataSourceCredentials };
    }

See also