简体   繁体   中英

crystal report is not showing any data

I am new to crystal reports. But i have designed the one crystal report by using help from google and asp.net forum. But after doing all the coding i am not able to view the crystal report after running through visual studio 2010. development environment (windows-7 32 bit,visual studio 2010 ,Crystal report V.13). My aspx looks like below:

 <%@ 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> 

And my aspx.cs looks like below:

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();
        }
    }
}

I debugged my code and i found that i am getting below error:

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

I am getting this error for all the attributes after HasRecords for the ReportDocument.

I googled and found that something is going in infinite loop or all breakpoints should be removed to solve this error.

But to my observation nothing is in infinite loop for the above mentioned code and I removed all the breakpoints but no luck.

Will anyone help me to solve this error i am not able to see crystal report after running the code.

I am getting blank page and getting this error For ReportDocument.

I set "PrintJobLimit" PROPERTY in registry = 250 and Enable 32-Applications on Application Pool in IIS = True

The reasons of the hang and of this error message are probably the same: there is something that takes a lot of time to compute. Both when you do it in code and in debugger.
It seems this kind of bug can happen simply when you are trying to watch at some variables who have to be thread safe but sometimes this framework implementation is not perfect....
In this case "HasRecords" doesn't appear in the code, so I suppose that it is watch window that causes the problem.

To avoid this problem : when stepping through code where variables are bound to windows or other controls, you don't show local variables or "auto" variables. Look at such things only when you are sure your variables are all safe to look at. And note that the error doesn't necessarily appear on the unsafe variables. Use the "immediate" window on safe (ie non-control) variables when operating in dangerous code.

Solution

1. step one

The solution is to work on IIS this way:

  • Copy aspnet_client folder from c:\\inetpub\\wwwroot folder to the new website root folder.

or (first one is easier, second one is better for maintenance)

  • Create a virtual directory called aspnet_client that points to
    c:\\inetpub\\wwwroot\\aspnet_client inside the new website

2. step two

copy this below to your 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. step three

Add this reference to the crystal report javascript in your master page or page rendering the report:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM