Crystalreportviewer无法加载任何例外

时间:2015-01-15 18:46:01

标签: c# asp.net asp.net-mvc-4 crystal-reports crystal-reports-2010

我陷入了在asp.net mvc4 razor视图中集成的crystalreportviewer(使用webform显示水晶报告)。使用IIS7.5,我已将aspnet_client文件夹(来自 C:\ inetpub \ wwwroot )放入我网站的root权限,并解决了未定义的bobj错误。 即使在尽一切可能之后,我也会在crystalreportviewer上看到这一点,并且在控制台中没有错误。

enter image description here

这是在我的aspx.cs页面加载事件中:

 ReportDocument rd = new ReportDocument();
 string strRptPath = Path.Combine(Server.MapPath("~/Reports"), strReportName);
 rd.Load(strRptPath);
 rd.SetDataSource(source);
 CrystalReportViewer1.ReportSource = rd;
 CrystalReportViewer1.DisplayToolbar = true;

它加载报表文档并设置其数据源和crystalreportviewer的reportsource但我在浏览器中看不到任何内容。

这是我的aspx页面(crystalreportviewer control):

<CR:CrystalReportViewer ID="CrystalReportViewer1" DisplayToolbar="True" Height="100%" runat="server" AutoDataBind="true" />

我连续两天没有输出就放弃了希望,如果你能指导我做错了什么或有任何建议。

1 个答案:

答案 0 :(得分:0)

当您在Visual Studio中,并单击Crystal Report的属性时,&#34; Build Action&#34;的值是多少。根据您与报表对象的交互方式,将其设置为&#34;内容&#34;可能有所帮助。

此外,为了简化故障排除,请使用没有子报告的简单报告。这是我使用的代码,用于说明子报告以及设置报告中所有表的连接。

        public static CrystalReportSource Crystal_SetDataSource(string reportName, object par1, object par2, object par3)
    {
        CrystalReportSource CrystalReportSource2 = new CrystalReportSource();

        CrystalReportSource2.CacheDuration = 10;

        CrystalReportSource2.Report.FileName = @"~\App_Pages\Secure\Reports\" + reportName;

        CrystalDecisions.CrystalReports.Engine.Database crDatabase = CrystalReportSource2.ReportDocument.Database;
        ConnectionInfo crConnectionInfo = new ConnectionInfo();
        crConnectionInfo.ServerName = server;
        crConnectionInfo.DatabaseName = db;
        crConnectionInfo.UserID = crystalUser;
        crConnectionInfo.Password = pwd;
        crConnectionInfo.IntegratedSecurity = false;


        // First we assign the connection to all tables in the main report
        TableLogOnInfo crTableLogOnInfo = new TableLogOnInfo();
        foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crDatabase.Tables)
        {
            crTableLogOnInfo = crTable.LogOnInfo;
            crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
            crTable.ApplyLogOnInfo(crTableLogOnInfo);
        }


        //SET DATASOURCE FOR EACH SUBREPORT IN REPORT
        foreach (CrystalDecisions.CrystalReports.Engine.Section section in CrystalReportSource2.ReportDocument.ReportDefinition.Sections)
        {
            // In each section we need to loop through all the reporting objects
            foreach (CrystalDecisions.CrystalReports.Engine.ReportObject reportObject in section.ReportObjects)
            {
                if (reportObject.Kind == ReportObjectKind.SubreportObject)
                {
                    SubreportObject subReport = (SubreportObject)reportObject;
                    ReportDocument subDocument = subReport.OpenSubreport(subReport.SubreportName);

                    foreach (CrystalDecisions.CrystalReports.Engine.Table table in subDocument.Database.Tables)
                    {
                        // Cache the logon info block
                        TableLogOnInfo logOnInfo = table.LogOnInfo;

                        // Set the connection
                        logOnInfo.ConnectionInfo = crConnectionInfo;

                        // Apply the connection to the table!
                        table.ApplyLogOnInfo(logOnInfo);
                    }
                }
            }
        }


        if (CrystalReportSource2.ReportDocument.DataSourceConnections.Count > 0)
            CrystalReportSource2.ReportDocument.DataSourceConnections[0].SetConnection(server, db, crystalUser, pwd);

        CrystalReportSource2.ReportDocument.SetDatabaseLogon(crystalUser, pwd, server, db);
        if (par1 != null)
            CrystalReportSource2.ReportDocument.SetParameterValue(0, par1);

        if (par2 != null)
            CrystalReportSource2.ReportDocument.SetParameterValue(1, par2);

        if (par3 != null)
            CrystalReportSource2.ReportDocument.SetParameterValue(2, par3);

        return CrystalReportSource2;
    }