//Here you can fetch Database Name dynamically and assign to Initial
Catalog for preparing dynamic connection string.
string conStr = @"Data Source=DILIPPC\SQLEXPRESS;Initial Catalog=Student";
// Fetch all datasources
var dataSources = this.reportViewer1.ServerReport.GetDataSources();
List<DataSourceCredentials> credentials = new List<DataSourceCredentials();
foreach (var dataSource in dataSources)
{
DataSourceCredentials credential = new DataSourceCredentials();
credential.Name = dataSource.Name;
credential.UserId = " "; // Wirte username of your connection
credential.Password = " "; // Wirte password of your connection
credentials.Add(credential);
}
this.reportViewer1.ServerReport.SetDataSourceCredentials(credentials);
// Added ConStr parameter and pass this parameter to SSRS report.
ReportParameter rptPar = new ReportParameter("ConStr", conStr);
reportViewer1.ServerReport.SetParameters(rptPar);