ReportDocument导出,保存或打印时出现异常

时间:2014-03-06 15:21:31

标签: c# crystal-reports reportdocument

这个可能很难解释。我有一个程序可以填写基于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)

提前感谢您的帮助。

0 个答案:

没有答案
相关问题