This one might be a tough one to explain. I've got a program which fills in a pre-built Crystal Report (CR 2011) based on an Oracle Database. I've applied the logon information to all the tables in the report (and all the tables in the 5 sub reports) through MSDN tutorial based code. If I do not add any code to do anything with the report once it's refreshed (such as saving it, or sending it to a printer) it will run through my code without issue. However, if I add any code that makes the program useful, it breaks with the below Exception.
Here is my relevant code:
try
{
for (Intcount = 1; Intcount < rName.Count(); Intcount++)
{
LogFile.LogMessage(path, sReportPath);
LogFile.LogMessage(path, sReportPath + rName.ElementAt(Intcount));
//This line is loading "C:\...\Policy Reinstatement.rpt" which is valid
cr.Load(sReportPath + rName.ElementAt(Intcount));
crConnectionInfo.ServerName = sDataSource;
crConnectionInfo.DatabaseName = "";
crConnectionInfo.UserID = sUserID;
crConnectionInfo.Password = sPassword;
cr.SetDatabaseLogon(crConnectionInfo.UserID, crConnectionInfo.Password,
crConnectionInfo.ServerName, crConnectionInfo.DatabaseName);
//Method for looping through each table in the report
//and applying the Connection Info to each of them
SetDBLogonForReport(crConnectionInfo, cr);
//Method for looping through all SubReports,
//then calling the SetDBLogonForReport method.
SetDBLogonForSubReports(crConnectionInfo, cr);
CrystalReportViewer rpt = new CrystalReportViewer();
rpt.ReportSource = cr;
try
{
rpt.Refresh();
}
catch (Exception ex)
{
//It does not throw on this exception
LogFile.LogError(path, ex);
throw;
}
cr.PrintToPrinter(1, false, 0, 1);
}
}
catch (Exception ex)
{
//It throws on this exception
LogFile.LogError(path, ex);
throw;
}
Here is the exception:
Message: Failed to open the connection.Policy Reinstatement {35A94093-A135-462DA5AA-F5FDD3E2D62B}.rpt
Source: CrystalDecisions.ReportAppServer.DataSetConversion
StackTrace: at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e)
at CrystalDecisions.ReportSource.EromReportSourceBase.HandleException(Exception exception)
at CrystalDecisions.ReportSource.EromReportSourceBase.GetLastPageNumber(ReportPageRequestContext reqContext)
at CrystalDecisions.CrystalReports.Engine.FormatEngine.PrintToPrinter(Int32 nCopies, Boolean collated, Int32 startPageN, Int32 endPageN)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.PrintToPrinter(Int32 nCopies, Boolean collated, Int32 startPageN, Int32 endPageN)
Inner Message:
Failed to open the connection.
Policy Reinstatement {35A94093-A135-462D-A5AA-F5FDD3E2D62B}.rpt
Inner Source: rptcontrollers.dll
Inner StackTrace: at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.GetLastPageNumber(RequestContext pRequestContext)
at CrystalDecisions.ReportSource.EromReportSourceBase.GetLastPageNumber(ReportPageRequestContext reqContext)
Thanks in advance for your help.