crystal 报告未显示任何数据

crystal report is not showing any data

我是 crystal 报告的新手。 但是我利用 google 和 asp.net 论坛的帮助设计了一份 crystal 报告。 但是在完成所有编码之后,我无法在 2010 年 运行 到 visual studio 之后查看 crystal 报告。 开发环境(windows-7 32 位,visual studio 2010,Crystal 报告 V.13)。 我的 aspx 如下所示:

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


<%@ 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 id="Head1" runat="server">
    <title></title>       
    <link href="8LcKSBVeHKaZoXGjmWViuQ==/Site.css" rel="stylesheet" type="text/css" />
</head>
<body style="background-color:#E6E6FA;">
    <form id="form1" runat="server">
    
      <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
            <Report FileName="CertsReportSapco.rpt">
            </Report>
        </CR:CrystalReportSource>

    
    <div>
 
    <CR:CrystalReportViewer ID="ReportViewer" runat="server" 
            GroupTreeImagesFolderUrl="" Height="1269px" 
            ToolbarImagesFolderUrl="" ToolPanelWidth="120px" Width="100%" 
            EnableDatabaseLogonPrompt="False" EnableParameterPrompt="False" 
            HasCrystalLogo="false" hasToggleGroupTreeButton="false" BestFitPage="false"   
            ToolPanelView="None" BorderColor="#006699" BorderStyle="Solid" 
            BorderWidth="2px" HasToggleParameterPanelButton="False" 
            ReuseParameterValuesOnRefresh="True" HasSearchButton="False" 
            onload="ReportViewer_Load" ReportSourceID="CrystalReportSource1" onunload="ReportViewer_Unload" 
            />
     
    </div>
    </form>
</body>
</html>

我的 aspx.cs 如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Globalization;
using CrystalDecisions.Web;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;

public partial class ReportSapco : System.Web.UI.Page
{
    public static readonly string _ConStr = ConfigurationManager.ConnectionStrings["CStr"].ToString();
    public static void CheckDB()
    {
        using (var _con = new SqlConnection(_ConStr))
        {
            if (_con.State == ConnectionState.Open)
            {
                _con.Close();
            }
        }
    }


    private DSCertsSapco GetData(string query)
    {
        SqlCommand cmd = new SqlCommand(query);
        using (SqlConnection con = new SqlConnection(_ConStr))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.Connection = con;
                sda.SelectCommand = cmd;
                using (DSCertsSapco dsCustomers = new DSCertsSapco())
                {
                    sda.Fill(dsCustomers, "TB_NewSapcoCerts");
                    return dsCustomers;
                }
            }
        }
    }

    protected void HomeBtn_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Default.aspx");
    }

    protected void BtnShowInfo_Click(object sender, EventArgs e)
    {

        string DateFrom = String.Format("{0}/{1}/01", GetCurYear(), DDownMonth.Text);
        string DateTo = String.Format("{0}/{1}/31", GetCurYear(), DDownMonth.Text);
        ReportDocument rpt = new ReportDocument();
        rpt.Load(Server.MapPath("CertsReportSapco.rpt"));
        DSCertsSapco dscerts = GetData("SELECT SuppCode,(SELECT SP_Name FROM TB_SupplierInfo WHERE (SP_Code=TB_NewSapcoCerts.SuppCode)) AS SuppName,PartNo,SerialNo,Code,PostedNo,(SELECT St_Name + ' ' + St_Family AS Expr1 FROM TB_StaffsInfo WHERE(St_PersCode=TB_NewSapcoCerts.SerialExporter)) AS SerialExporter,SerialIssuedDate,ID,SerialExporter as Perscode FROM TB_NewSapcoCerts where SerialExporter=N'" + int.Parse(Session["PersCode"].ToString()) + "' and suppcode='" + DDownSupp.Text + "' and SerialIssuedDate between '" + DateFrom + "' and '" + DateTo + "' and SerialStat<>6 order by SerialIssuedDate");
        if (dscerts.Tables[0].Rows.Count > 0)
        {
            rpt.SetDataSource(dscerts);
            rpt.SetParameterValue("Karfarma", "ساپکو");
            rpt.SetParameterValue("Mah", DDownMonth.Text);
            rpt.SetParameterValue("Personeli", Session["PersCode"].ToString());
            rpt.SetParameterValue("PersName", Session["PersName"].ToString());
            ReportViewer.ReportSource = rpt;
            ReportViewer.DataBind();
        }
        else
        {
            ReportDocument rpt2 = new ReportDocument();
            rpt2.Load(Server.MapPath("CertsReportSapco.rpt"));
            rpt2.SetDataSource("");
            rpt2.SetParameterValue("Karfarma", "");
            rpt2.SetParameterValue("Mah", "");
            rpt2.SetParameterValue("Personeli", "");
            rpt2.SetParameterValue("PersName", "");
            ReportViewer.ReportSource = rpt2;
        }

    }
    protected void SapcoPrint_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/ReportSaze.aspx");
    }
    protected void EpcoPrint_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/ReportEpco.aspx");
    }
    protected void ReportViewer_Load(object sender, EventArgs e)
    {
        string DateFrom = String.Format("{0}/{1}/01", GetCurYear(), DDownMonth.Text);
        string DateTo = String.Format("{0}/{1}/31", GetCurYear(), DDownMonth.Text);

        ReportDocument rpt = new ReportDocument();
        rpt.Load(Server.MapPath("~/CertsReportSapco.rpt"));
        DSCertsSapco dscerts = GetData("SELECT SuppCode,(SELECT SP_Name FROM TB_SupplierInfo WHERE (SP_Code=TB_NewSapcoCerts.SuppCode)) AS SuppName,PartNo,SerialNo,Code,PostedNo,(SELECT St_Name + ' ' + St_Family AS Expr1 FROM TB_StaffsInfo WHERE(St_PersCode=TB_NewSapcoCerts.SerialExporter)) AS SerialExporter,SerialIssuedDate,ID,SerialExporter as Perscode FROM TB_NewSapcoCerts where SerialExporter=N'" + int.Parse(Session["PersCode"].ToString()) + "' and suppcode='" + DDownSupp.Text + "' and SerialIssuedDate between '" + DateFrom + "' and '" + DateTo + "' and SerialStat<>6 order by SerialIssuedDate");
        if (dscerts.Tables[0].Rows.Count > 0)
        {
            rpt.SetDataSource(dscerts);
            rpt.SetParameterValue("Karfarma", "ساپکو");
            rpt.SetParameterValue("Mah", DDownMonth.Text);
            rpt.SetParameterValue("Personeli", Session["PersCode"].ToString());
            rpt.SetParameterValue("PersName", Session["PersName"].ToString());
            ReportViewer.ReportSource = rpt;
        }
        else
        {
            ReportDocument rpt2 = new ReportDocument();
            rpt2.Load(Server.MapPath("CertsReportSapco.rpt"));
            rpt2.SetDataSource("");
            rpt2.SetParameterValue("Karfarma", "");
            rpt2.SetParameterValue("Mah", "");
            rpt2.SetParameterValue("Personeli", "");
            rpt2.SetParameterValue("PersName", "");
            ReportViewer.ReportSource = rpt2;
        }
    }
    protected void ReportViewer_Unload(object sender, EventArgs e)
    {
        if (ReportViewer != null)
        {
           ReportViewer.ReportSource = null;
           ReportViewer.Dispose();
        }
    }
}

我调试了我的代码,发现我遇到了以下错误:

HasRecords = Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation crystal reports

对于 ReportDocument 的 HasRecords 之后的所有属性,我都收到此错误。

我 googled 发现某些东西进入无限循环或应该删除所有断点以解决此错误。

但据我观察,上面提到的代码没有任何无限循环,我删除了所有断点,但运气不好。

谁能帮我解决这个错误,我无法在 运行 代码后看到 crystal 报告。

我得到的是空白页并收到此 ReportDocument 错误。

我在注册表中设置 "PrintJobLimit" 属性 = 250 并在 IIS 中的应用程序池上启用 32 个应用程序 = True

挂起的原因和此错误消息的原因可能是相同的:有些东西需要花费大量时间来计算。无论是在代码中还是在调试器中执行此操作。
似乎这种错误可能只是在您尝试观察某些必须是线程安全的变量时才会发生,但有时这个框架实现并不完美....
在这种情况下 "HasRecords" 没有出现在代码中,所以我认为是 watch window 导致了问题。

为避免此问题:当逐步执行变量绑定到 windows 或其他控件的代码时,您不会显示局部变量或 "auto" 变量。仅当您确定您的变量都可以安全查看时才查看此类内容。并注意错误不一定出现在不安全的变量上。在危险代码中操作时,对安全(即非控制)变量使用 "immediate" window。

解决方案

1.第一步

解决方法是这样在 IIS 上工作:

  • aspnet_client 文件夹从 c:\inetpub\wwwroot 文件夹复制到新文件夹 网站根文件夹。

或(第一个更容易,第二个更好维护)

  • 创建一个名为 aspnet_client 的虚拟目录,指向
    c:\inetpub\wwwroot\aspnet_client 新网站里面

2。第二步

将下面的内容复制到您的 web.config

1。

<configSections>
<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" />
       <section name="crystalReportViewer" type="System.Configuration.NameValueSectionHandler" />
  </sectionGroup>
</sectionGroup>
  </configSections>

2.

<businessObjects>
      <crystalReports>
        <rptBuildProvider>
          <add embedRptInResource="true" />
        </rptBuildProvider>
        <crystalReportViewer>
              <add key="ResourceUri" value="/crystalreportviewers13" />
      </crystalReportViewer>
      </crystalReports>
    </businessObjects>

3。第三步

在母版页或呈现报告的页面中添加对 crystal 报告 javascript 的引用:

<script src='<%=ResolveUrl("~/crystalreportviewers13/js/crviewer/crv.js")%>'type="text/javascript"></script>