0
votes

I am attempting to add a Crystal Report Viewer to an asp.net web app. We are using reports that were created for our desktop application so they are already created and functional. We are connecting to the same database with the same query across both platforms and the database and query is set up in the report designer.

Here's a preview from one of the reports in Visual Studio Pro 2015 in the asp.net project: enter image description here

I have added the following line to my Reports.aspx page:

<CR:CrystalReportViewer ID="crptViewer" runat="server" AutoDataBind="true" />

I added a "Crystalreportviewers13" folder to the root of the application directory with the content of crystal report installation.

I have added the following to my web.config file:

<configuration>
  <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>
   <businessObjects>
    <crystalReports>
      <rptBuildProvider>
        <add embedRptInResource="true"/>
     </rptBuildProvider>
    <crystalReportViewer>
              <add key="ResourceUri" value="/crystalreportviewers13" />
      </crystalReportViewer>
    </crystalReports>
  </businessObjects>

I have tried several strategies on the code behind based on different stack overflow suggestions. Here's what I've tried so far:

On Button Click:

public partial class Reports : System.Web.UI.Page

{

ReportDocument rptDocument;
protected void Page_Load(object sender, EventArgs e)
    {
        string stack = "Page_Load()(Reports.aspx.cs)";
        try
        {
            if (Session["report"] != null)
            {
                crptViewer.ReportSource = Session["report"];

            }
        }
        catch (Exception EX)
        {
            IOClass.appendLog("Error in " + stack, EX.Message);
        }
    }

   //Button Click
   protected void generateReport(object sender, EventArgs e)
    {

        rptDocument = new ReportDocument();
        rptDocument.Load(Server.MapPath("~/Crystal/UserListing.rpt"));

        rptDocument.SetParameterValue("Company", 1);

        Session["report"] = rptDocument;


    }
}

and On Load:

public partial class Reports : System.Web.UI.Page
{

    ReportDocument rptDocument;
    protected void Page_Load(object sender, EventArgs e)
    {
        string stack = "Page_Load()(Reports.aspx.cs)";
        try
        {
           rptDocument = new ReportDocument();
           rptDocument.Load(Server.MapPath("~\\Crystal\\UserListing.rpt"));
           crptViewer.ReportSource = rptDocument;

           //I have tried with and without the following:
           //crptViewer.DataBind();
           //and
           //crptViewer.RefreshReport();
        }
        catch (Exception EX)
        {
            IOClass.appendLog("Error in " + stack, EX.Message);
        }
    }
}

When the page loads in both cases this is what I get:

enter image description here

I'm doing exception logging on the load function and I do not get any exceptions.

Any ideas what I'm doing wrong here? Let me know if I can provide any other information.

Thank you for your time

1
This is running on IIS server or VS IIS? Problably this is most related with IIS configuration for Crystal and permissions, also about login inormation for your report. I also had a problem like this and I need to dig a lot over internet. First of all lets try this, if it didn't work I'll help you with IIS config - stackoverflow.com/questions/19976636/…Andrew Paes
Thank you for your comment. I have modified my function to include the Connection Info from the stack overflow that your referenced but it did not help. I did get more information from it though. The TestConnectivity() function in the ApplyLogOnInfo section returned true. I assume that means the the connection to the database was successful? I have also modified the security of the .rpt file to allow full control to my user. To answer your question, I am running the app on Web Matrix 3 but I have also tried to run it through IIS (Version 10.0.14393.0)James Sumner
Could you read this other post and tell me if you can use something from there to your environment? stackoverflow.com/questions/28681406/…Andrew Paes
Unfortunately, nothing from that post was helpful.James Sumner

1 Answers

0
votes

Remove <asp:Content> on aspx and use the default html page like this...

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="myproject.WebForm1" %>

<%@ Register assembly="CrystalDecisions.Web, Version=13.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
        <script type="text/javascript" src="/crystalreportviewers13/js/crviewer/crv.js">
        </script> 
</head>
<body>
    <form id="form1" runat="server">
        <div>
		    <asp:Button ID="btnShowReport" runat="server" Text="Show Report" OnClick="btnShowReport_Click" />
            <CR:CrystalReportViewer ID="JobRepairReportViewer" runat="server" AutoDataBind="true" />
        </div>
    </form>
</body>
</html>

On Load in 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.Collections;
using System.Data;
using System.Diagnostics;
using CrystalDecisions.CrystalReports.Engine;

namespace iconequipment
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnShowReport_Click(object sender, EventArgs e)
        {
            ReportDocument rpt = new ReportDocument();
            rpt.Load(Server.MapPath("JobRepairReport.rpt"));
            //rpt.SetParameterValue("JobID", this.txtJobID.Text);
            this.JobRepairReportViewer.ReportSource = rpt;
            this.JobRepairReportViewer.RefreshReport();
        }
    }
}