Hello everyone,
I am humbly asking for anybody's help in a matter that seems to go way beyond my understanding. I am trying to load a .rpt file based on a stored procedure that receives only one parameter, Connect to a SQL server database to get a dataset for the report and then export the report in PDF format. But the code always breaks in the line where export to PDF occurs. I would like some help in that regard since I tried almost everything advised online in that regard.
Thanks so much.
public static void GeneratePhoneReportMemberServicesReport()
{
ReportDocument objReportDocument = new ReportDocument(); //Report document
ConnectionInfo connectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
//Step 1. Connection to WEB2 to execute the script EXEC_rptPhoneAnswerPerformanceEx_Com.sql
string crystalPhoneReportPerformancePath = System.Configuration.ConfigurationManager.AppSettings["CrystalPhoneReportsPath"].ToString();
string crystalPhoneReportOutputMemberServicesPath = @"C:\Users\pma\Documents\Temp\Reports\";
string crystalPhoneReportSetonPath = System.Configuration.ConfigurationManager.AppSettings["SetonReportPath"].ToString();
string crystalSetonPhoneReportName = System.Configuration.ConfigurationManager.AppSettings["SetonPhoneReportM17"].ToString();
string crystalNHPNYPrototypePhoneReportPath = System.Configuration.ConfigurationManager.AppSettings["NHPNYPrototypePhoneReportsPath"].ToString();
//Step 3. Go to the report location \\bhs05wd001\dev\CrystalReportsDev\Phone Reports and refresh every single Crystal Reports
// a) Retrieve the partial connection string from Web2 ReportsProduction
SqlConnectionStringBuilder serverConnectionInfo = new SqlConnectionStringBuilder(DataAccess.GetConnectionString(Constants.WEB2_REPORTSPRODUCTION));
connectionInfo.ServerName = serverConnectionInfo.DataSource; ;
connectionInfo.DatabaseName = serverConnectionInfo.InitialCatalog;
connectionInfo.UserID = serverConnectionInfo.UserID;
connectionInfo.Password = serverConnectionInfo.Password;
//b) Generate each Phone report
try
{
string filterExtension = "*.rpt";
string substringInFileName = "M1_2_PhoneAnswerPerformance";
List<ReportFile> reportFiles = Utilities.GetFilesFromDirectory(@crystalPhoneReportPerformancePath, filterExtension, substringInFileName).ToList();
foreach (ReportFile reportFile in reportFiles)
{
string reportFileNameWithoutExtension = Path.GetFileNameWithoutExtension(reportFile.FileName);
objReportDocument.Load(string.Format("{0}{1}",@crystalPhoneReportPerformancePath, reportFile.FileName)); //objReportBase.GenerateReport(reportFile.FileName, ParameterArrayList, crystalPhoneReportPerformancePath);
foreach(CrystalDecisions.CrystalReports.Engine.Table table in objReportDocument.Database.Tables )
{
table.LogOnInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(table.LogOnInfo);
}
//objReportDocument.SetDatabaseLogon(serverConnectionInfo.UserID, serverConnectionInfo.Password,serverConnectionInfo.DataSource,serverConnectionInfo.InitialCatalog);
objReportDocument.SetParameterValue(0, "No"); // the parameter is passed here i.e Index and value
objReportDocument.SetDataSource(GetPhoneData(reportFileNameWithoutExtension, Constants.WEB2_REPORTSPRODUCTION));
//Save output report
string outputDestination = string.Format("{0}{1}{2}", @crystalPhoneReportOutputMemberServicesPath, Path.GetFileNameWithoutExtension(reportFile.FileName), ".pdf");
objReportDocument.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, @"C:\dell\file.pdf"); //This the line where the code breaks with the error "Missing parameter values".
//Export this file in Excel format as well
if (reportFile.FileName.Contains("CLHS_M1_2_PhoneAnswerPerformanceGraphs_Combined"))
{
// objReportDocument.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.ExcelWorkbook, string.Format("{0}{1}{2}", @crystalPhoneReportOutputMemberServicesPath, Path.GetFileNameWithoutExtension(reportFile.FileName), ".xls"));
objCrystalReport.ExportToDisk(ExportFormatType.PortableDocFormat, string.Format("{0}{1}{2}", @crystalPhoneReportOutputMemberServicesPath, Path.GetFileNameWithoutExtension(reportFile.FileName), ".xls"));
}
}
//release those resources
objReportDocument.Dispose();
objReportDocument.Close();
objReportDocument = null;
}