You can use below code to generate the report
private void IntReport(string rptPath, string strServerName, string strDataBase, string strUserName, string strPassword)
{
try {
ReportDocument crReportDoc = new ReportDocument();
ConnectionInfo crpConnectionInfo = new ConnectionInfo();
TableLogOnInfo crpTableLogonInfo = new TableLogOnInfo();
Table tblCurrent = default(Table);
Sections crSections = default(Sections);
SubreportObject crSubreportObject = default(SubreportObject);
ReportObjects crReportObjects = default(ReportObjects);
ReportDocument crSubreportDocument = default(ReportDocument);
_crReportDoc.Load(rptPath);
crpConnectionInfo.AllowCustomConnection = true;
crpConnectionInfo.ServerName = strServerName;
crpConnectionInfo.DatabaseName = strDataBase;
crpConnectionInfo.UserID = strUserName;
crpConnectionInfo.Password = strPassword;
foreach ( tblCurrent in _crReportDoc.Database.Tables) {
crpTableLogonInfo = tblCurrent.LogOnInfo;
crpTableLogonInfo.ConnectionInfo = crpConnectionInfo;
tblCurrent.ApplyLogOnInfo(crpTableLogonInfo);
}
crSections = crReportDoc.ReportDefinition.Sections;
foreach (Section crSection in crSections) {
crReportObjects = crSection.ReportObjects;
foreach (ReportObject crReportObject in crReportObjects) {
if (crReportObject.Kind == ReportObjectKind.SubreportObject) {
crSubreportObject = (SubreportObject)crReportObject;
crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);
foreach ( tblCurrent in crSubreportDocument.Database.Tables) {
crpTableLogonInfo = tblCurrent.LogOnInfo;
crpTableLogonInfo.ConnectionInfo = crpConnectionInfo;
tblCurrent.ApplyLogOnInfo(crpTableLogonInfo);
}
}
}
}
crReportDoc.VerifyDatabase();
} catch (Exception ex) {
throw ex;
}
}