Search results
Suggest a FeaturePDF

How to change the datasource dynamically

You have to use the OnInitReportOptions method to change the datasource dynamically in the web API controller. Please follow these steps,

    [NonAction]
    public void OnInitReportOptions(ReportViewerOptions reportOption)
    {
        string connectionString = "Data Source = <instancename>; Initial Catalog = <database>; User ID = <username>; Password = <password>";
        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.

Having trouble getting help?
Contact Support
Having trouble getting help?
Contact Support