Articles in this section
Category / Section

How to change the data source dynamically


You have to use the reportOption.ReportModel.DataSourceCredentials available with the OnInitReportOptions method to dynamically change the data source in the web API controller. The following code sample shows how to change the connection string of the AdventureWorks data source in the report.

    public void OnInitReportOptions(ReportViewerOptions reportOption)
        DataSourceCredentials dataSourceCredentials = new DataSourceCredentials();

        string connectionString = "Data Source =; Initial Catalog = AdventureWorks; User ID = 'demoreadonly@data-platform-demo'; Password = 'N@c)=Y8s*1&dh'";

        //You have to provide the shared data source name used with the report or the data source name available with the report.
        dataSourceCredentials.Name = "AdventureWorks";
        dataSourceCredentials.ConnectionString = connectionString;
        reportOption.ReportModel.DataSourceCredentials = new List<DataSourceCredentials> { dataSourceCredentials };
‚ÄčYou can find the following help documentation for how to change data sources based on the application parameters in various platforms.
Was this article useful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied