Crystal Reports Integration

0
0

I have read with interest the posts relating to Crystal Report integration and the problem I am experiencing would seem to relate to the target framework.

Crystal Reports seems to support up to Dot Net Framework 4.0 with WiseJ supporting from Dot Net Framework 4.5 on.

In would see no issue in using the Crystal Report viewer (as I did with Visual Web Gui) if either WiseJ supported Dot Net Framework 4.0 (in an attempt to get the report viewer to work I dropped the framework to 4.0 and WiseJ failed to work).

I have attempted to integrate in bot VS2012 / Vs2013 and VS2015 but with no success.

Does anyone have any suggestions, other than waiting for Crystal Reports to support Dot Net Framework 4.5 and above.

Thanks

Andrew

  • You must to post comments
0
0

Try starting a project in .Net 2 – then add the references, then switch back. I’ve had this trouble since using .Net 4 years ago! Be careful with losing other references etc though. I’ve even taken to copying references from a working project into new ones by editing the csproj file!

Here’s an example of what I copy across into the <ItemGroup> section in the project file. We’re using 13.0.24 so the Version number may differ on your system:

    <Reference Include=”CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL”>
      <SpecificVersion>False</SpecificVersion>
      <Private>True</Private>
    </Reference>
    <Reference Include=”CrystalDecisions.ReportSource, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL”>
      <SpecificVersion>False</SpecificVersion>
      <Private>True</Private>
    </Reference>
    <Reference Include=”CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL”>
      <SpecificVersion>False</SpecificVersion>
      <Private>True</Private>
    </Reference>
    <Reference Include=”CrystalDecisions.Windows.Forms, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL”>
      <SpecificVersion>False</SpecificVersion>
      <Private>True</Private>
    </Reference>
  • You must to post comments
0
0

This configuration has worked for me and is in production with customers (not clean and neat, but functional – And before you knock my code style, please remember that I was brand new to coding in C# when this was originally written):

  1. Add References in your project to CrystalDescisions.CrystalReports.Engine, CrystalDescisions.Report.Source, CrystalDescisions.Shared & CrystalDescisions.Web
  2. Check that the Web.config file has a sectionGroup called businessObjects
  3. In the Web.config, if the assemblies item has anything other than CrystalDescisions.CrystalReports.Engine, then Comment these out (they are not ness and can cause runtime errors)
  4. Create a standard aspx page and include <CR:CrystalReportViewer ID=”crystalReportViewer” runat=”server” AutoDataBind=”true” /> (My page is simply called report.aspx)
  5. In the code behind of the aspx page (note this is my setup, you can modify as you need):
    a. see below for contents of sample report.aspx.cs
  6. Create a base form to hold the aspx file, can be an IFrame if web, or in my case a AspNetPanel and point it at ANOTHER aspx file (otherwise it tries to load the report before it’s ready – I used a blank page just called loading.aspx)
    a. Set a timer on your form or in you scripts, to prevent trying to load before the DOM is ready (mine is set to 1 second, since the timer only starts one DOM is ready anyway). If using Javascript to call the IFrame, then timeout may not be ness as long as you only call the report.aspx file after DOM is ready.
    b. In the timer you now call the aspx page to fill the viewer or Frame with parameters vs holding the rpt filename and xfn holding the xml filename
  7. Create the tempreports (or whatever you decide is the path to temporary XML files) folder under your site and ensure that sufficient rights are assigned
  8. Your Crystal Report must now write to an XML file in the temporary directory, this part is up to you to call from your application whereever you need. You can do this with DataSet.WriteXml(filename,XmlWriteMode.WriteSchema)
  9. If ness, install the same version of the Crystal Report runtimes onto your server
  10. Lastly, don’t forget to include code somewhere to remove all the temporary xml files from time to time

Notes: Even though there are later versions I keep my Crystal at version 13 across sites (since I still have VB sites and VS2013 developed systems out there)

Hope this helps someone.

 

Couldn’t attach so code for report.aspx.cs below:

using System;
using System.Data;
using CrystalDecisions.Web;
using CrystalDecisions.CrystalReports.Engine;

namespace MyApp {
    public partial class report : System.Web.UI.Page {
        ReportDocument viewerSource = null;
        
        protected void Page_Load(object sender, EventArgs e) {

            string qsXmlFilename = Request.QueryString["xfn"];
            string qsViewerSource = Request.QueryString["vs"];

            Type t = Type.GetType(qsViewerSource);

            viewerSource = (ReportDocument)Activator.CreateInstance(t);

            clsReporting.printSetViewer(viewerSource, qsXmlFilename);
            
            crystalReportViewer.ReportSource = viewerSource;
            crystalReportViewer.DisplayStatusbar = false;
            crystalReportViewer.DisplayToolbar = true;
            crystalReportViewer.EnableDrillDown = false;
            crystalReportViewer.EnableDatabaseLogonPrompt = false;
            crystalReportViewer.EnableParameterPrompt = false;
            crystalReportViewer.EnableToolTips = false;
            crystalReportViewer.HasCrystalLogo = false;
            crystalReportViewer.HasDrilldownTabs = false;
            crystalReportViewer.HasDrillUpButton = false;
            crystalReportViewer.HasPageNavigationButtons = true;
            crystalReportViewer.HasToggleGroupTreeButton = false;
            crystalReportViewer.HasToggleParameterPanelButton = false;
            crystalReportViewer.PrintMode = CrystalDecisions.Web.PrintMode.Pdf;
            crystalReportViewer.SeparatePages = false;
            crystalReportViewer.ShowAllPageIds = false;
            crystalReportViewer.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
        }

    // Usually this would be somewhere else in your project, not in the report.aspx.cs code behind
        public static void printSetViewer(ReportDocument objReport, string tmpFile) {

            string tmpPath += "~\tempreports";

            DataSet ds = new DataSet();
            ds.ReadXml(tmpPath + @"\" + tmpFile + ".xml"); //Temp XML file is created on server by another process
            
            objReport.Load(objReport.FileName.ToString());
            objReport.SetDatabaseLogon("", "", tmpFile, ds.DataSetName.ToString());
            objReport.SetDataSource(ds);

            ConnectionInfo crConnInfo = new ConnectionInfo();
            crConnInfo.ServerName = tmpFile;
            crConnInfo.DatabaseName = ds.DataSetName.ToString();
            crConnInfo.UserID = "";
            crConnInfo.Password = "";
            crConnInfo.Type = ConnectionInfoType.MetaData;

            TableLogOnInfo tblTempLogonInfo = new TableLogOnInfo();
            // This prevent the frustrating Database Login Errors
            foreach (Table tbl in objReport.Database.Tables)
            {
                tblTempLogonInfo = tbl.LogOnInfo;
                tblTempLogonInfo.ConnectionInfo = crConnInfo;
                tblTempLogonInfo.TableName = tbl.Name;
                tblTempLogonInfo.ReportName = objReport.Name;
                tbl.ApplyLogOnInfo(tblTempLogonInfo);
                tbl.Location = tbl.Name;
                tbl.SetDataSource(ds.Tables[tbl.ToString()]);
            }
    }
}
  • You must to post comments
0
0

Hi Thomas,

I’m running Crystal Reports 13 and have tried all service packs (currently sp 19)

In particular it’s the Crystal Reports Viewer I am having trouble with – just cant seem to get it as an object in the toolbox.

I have done this without trouble in Visual Web Gui which is somewhat similar to WiseJ

Thanks for your help.

Andrew

  • Thomas (ITG)
    Hi Andrew, if you cannot see the Crystal Reports viewer in the Visual Studio toolbox, please get in touch with SAP. Sounds like a setup issue on your machine outside the scope of Wisej.
  • You must to post comments
0
0

Hi Andrew,

which version of Crystal Reports are you using?

Best wishes
Thomas

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.