服务器上的加载报告失败 - Crystal Reports

时间:2014-05-27 15:32:33

标签: c# asp.net crystal-reports

我有一个水晶报表查看器页面,可以很好地在我的桌面开发计算机上显示报表。我用于此查看器页面的代码是:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LoyalitySystem;
using System.Configuration;
using HQ.DatabaseGateway;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.IO;

public partial class WebPages_DynamicReports_CrystalReportViewerPage : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string reportPath = Server.MapPath((string)Utils.GetSessionNavigator(this).GetDataFromCurrentPage(PageParams.Reports.Report));
        ReportDocument rep = new ReportDocument();

        try
        {
            if (!File.Exists(reportPath))
            {
                Response.Write("The specified report does not exist \n");
            }

            rep.Load(reportPath);
            LoadReport(rep);
            this.CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
            this.CrystalReportViewer1.HasToggleGroupTreeButton = false;
            this.CrystalReportViewer1.ReportSource = rep;
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }

    private bool LoadReport(ReportDocument doc)
    {
        TableLogOnInfo crTableLogonInfo;
        Sections crSections;
        Database crDatabase;
        Tables crTables;
        ReportDocument crSubreportDocument;
        ReportObjects crReportObjects;
        SubreportObject crSubreportObject;

        try
        {
            ConnectionInfo con = new ConnectionInfo();
            con.ServerName = ConfigurationManager.AppSettings["dbsource"];
            con.DatabaseName = Utils.GetSessionNavigator(this).UserData.DatabaseName;
            con.UserID = ConfigurationManager.AppSettings["uid"];
            con.Password = ConfigurationManager.AppSettings["pwd"];
            crDatabase = doc.Database;
            crTables = crDatabase.Tables;

            //loop through all the tables and pass in the connection info
            foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
            {
                crTableLogonInfo = crTable.LogOnInfo;
                crTableLogonInfo.ConnectionInfo = con;
                crTable.ApplyLogOnInfo(crTableLogonInfo);
            }

            // set the crSections object to the current report's sections
            crSections = doc.ReportDefinition.Sections;

            // loop through all the sections to find all the report objects
            foreach (Section crSection in crSections)
            {
                crReportObjects = crSection.ReportObjects;
                // loop through all the report objects to find all the subreports
                foreach (ReportObject crReportObject in crReportObjects)
                {
                    if (crReportObject.Kind == ReportObjectKind.SubreportObject)
                    {
                        crSubreportObject = (SubreportObject)crReportObject;

                        // open the subreport object
                        crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);

                        // set the database and tables objects to work with the subreport
                        crDatabase = crSubreportDocument.Database;
                        crTables = crDatabase.Tables;

                        // loop through all the tables in the subreport and 
                        // set up the connection info and apply it to the tables
                        foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
                        {
                            crTableLogonInfo = crTable.LogOnInfo;
                            crTableLogonInfo.ConnectionInfo = con;
                            crTable.ApplyLogOnInfo(crTableLogonInfo);
                        }
                    }
                }
            }
        }
        catch (Exception e)
        {
            Response.Write(e.Message);
            return false;
        }

        return true;
    }
}

如前所述,这在本地托管我的应用程序时工作正常,但在生产服务器上,我在运行的每个报告上都收到Load Report Failed,并且从我的检查中查看文件是否存在,我可以看到正在找到请求的文件。

我的.aspx标记是:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CrystalReportViewerPage.aspx.cs"
    Inherits="WebPages_DynamicReports_CrystalReportViewerPage" %>

<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
    Namespace="CrystalDecisions.Web" TagPrefix="cr" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>CrystalReportViewer</title>
</head>
<body>
    <form id="form1" runat="server">
    <cr:CrystalReportViewer ID="CrystalReportViewer1" runat="server" HasCrystalLogo="False" />
    </form>
</body>
</html>

我的web.config文件包含:

    <sectionGroup name="businessObjects">
        <sectionGroup name="crystalReports">
            <section name="rptBuildProvider" type="CrystalDecisions.Shared.RptBuildProviderHandler, CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, Custom=null"/>
        </sectionGroup>
    </sectionGroup>

        <assemblies>
            <add assembly="CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
            <add assembly="CrystalDecisions.ReportSource, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
            <add assembly="CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
            <add assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
            <add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
        </assemblies>
        <buildProviders>
            <add extension=".rpt" type="CrystalDecisions.Web.Compilation.RptBuildProvider, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
        </buildProviders>

我在不同时间在我的Windows 2008 R2 Datacenter服务器上安装了CRforVS_redist_install_64bit_13_0_2CRforVS_redist_install_32bit_13_0_2可再发行服务器,但都无法解决问题。该应用程序连接到Amazon RDS SQL Server实例,该实例位于Amazon EC2实例本身上。

我已经在互联网上搜索了一段时间来找到这个问题的解决方案,但显然加载报告失败的消息在其含义上相当广泛,所以我希望我可以帮助解决这个问题,特别是这个问题。

我已经坚持这个问题超过一个星期了所以如果能提供任何帮助我将不胜感激。

1 个答案:

答案 0 :(得分:3)

此消息通常表明使用提供的路径无法使用报告。如果未安装运行时,您将收到不同的消息。在您的情况下,所有内容都已正确安装,但报告在reportPath + rpName中不可用。您可以调试和检查reportPath + rpName是否指向以及报告是否真的存在。尝试使用Path.Combine(reportPath,rpName) - 如果需要,它将添加\。还要检查IIS是否有权访问reportPath文件夹中的报告。