Articles in this section
Category / Section

How to Change SQL DataSource Credentials Dynamically in Bold Reports Report Writer.

Published:
Updated:

BoldReports allows you to change the datasource credentials dynamically at runtime for the Report Writer control. This can be useful in cases where you need to change the connection string at runtime or render the report with different datasource credentials. For example, you can use this feature to share a report with different users who have different datasource credentials. This can also be useful in cases where the connection string changes frequently.

To change the datasource credentials dynamically, you can use the following steps:

  1. Get the datasource available in the report using the writer.GetDataSource() method.
  2. Change the datasource credentials dynamically.
  3. Use the modified datasource credentials to render the report and export.
    The following code sample shows how to change the connection string of the AdventureWorks data source in the report:
public IActionResult Export(string writerFormat)
        {
            FileStream reportStream = new FileStream(_hostingEnvironment.WebRootPath + @"\Resources\sales-order-detail.rdl", FileMode.Open, FileAccess.Read);
            
            BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter(reportStream);
            List<ReportDataSourceInfo> datasources = writer.GetDataSources();

            string connectionString = "Data Source =dataplatformdemodata.syncfusion.com ; Initial Catalog = AdventureWorks; User ID = 'demoreadonly@data-platform-demo'; Password = 'AN@c)=Y8s*1&dh'";
            DataSourceCredentials DataSourceCredentials = new DataSourceCredentials();
            DataSourceCredentials.Name = datasources[0].Name;
            DataSourceCredentials.ConnectionString = connectionString;
            writer.SetDataSourceCredentials(new List<DataSourceCredentials> () { DataSourceCredentials });

            ...
            ...
            ...
        }
Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied