これは説明するのが難しいかもしれません。Oracle データベースに基づいて、事前に作成された Crystal Report (CR 2011) に入力するプログラムがあります。MSDN チュートリアル ベースのコードを使用して、レポート内のすべてのテーブル (および 5 つのサブ レポート内のすべてのテーブル) にログオン情報を適用しました。レポートが更新されたら (レポートを保存したり、プリンターに送信したりするなど)、何も実行するコードを追加しないと、コードは問題なく実行されます。ただし、プログラムを便利にするコードを追加すると、以下の例外で壊れます。
これが私の関連コードです:
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;
}
例外は次のとおりです。
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)
よろしくお願いします。