3

I am developing a simple app using Crystal Report (Version 13.0) and .NET Framework 4.0 as well as VS 2013. What i am doing is that i have a Crystal report viewer on the form which is supposed to show/load my report when button is clicked. My code to load a report is:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
namespace CystalReportsApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                ReportDocument rpt = new ReportDocument();
                rpt.Load(@"e:<path>\CystalReportsApp\CystalReportsApp\CrystalReport1.rpt");
                crystalReportViewer1.ReportSource = rpt;
                crystalReportViewer1.Refresh();
            }
            catch (Exception ex)
            {

                throw;
            }
        }
    }
}

Problem i am getting is that whenever i click button, an exception occurs saying this:

CrystalDecisions.Shared.CrystalReportsException was unhandled
HResult=-2146232832
Message=Load report failed.
Source=CrystalDecisions.CrystalReports.Engine
StackTrace:
   at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened()
   at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob)
   at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename)
   at CystalReportsApp.Form1.button1_Click(Object sender, EventArgs e) in e:\<path>\CystalReportsApp\Form1.cs:line 32
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at CystalReportsApp.Program.Main() in e:\<path>\CystalReportsApp\Program.cs:line 19
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Runtime.InteropServices.COMException
    HResult=-2147467259
    Message=The system cannot find the path specified.    
    Source=Analysis Server
    ErrorCode=-2147467259
    StackTrace:
         at CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocumentClass.Open(Object& DocumentPath, Int32 Options)
         at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.Open(Object& DocumentPath, Int32 Options)
         at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened()
       InnerException: 

Solutions i have tried are:

  1. Checked the path again and again.
  2. Checking file permissions on the temp folder as well as on the folder where my report resides.
  3. Checking stackoverflow for the answer but couldn't find an answer regarding my problem's details.

But all in vein. Can somebody please tell me as what's going behind the scene?

UPDATED Alongside this forum, i had also posted this question at SAP crystal reports' forum for which somebody answered as to just remove @ sign from the path. But as i remove @ sign, "Unrecognized escape sequence" errors come. Please help! Answer by SAP COMMUNITY NETWORK

Sameer
  • 71
  • 1
  • 1
  • 8
  • I have set the Build Action property of Crystalreport to Content and Copy to output directory as "Copy Always"... – Sameer Nov 24 '14 at 16:09
  • 1
    can you show us line 19 please in your code?? – Abdulrahman_88 Nov 25 '14 at 06:46
  • There is nothing at line number 19 Sir. For your convenience, i am going to put all my code (comprising of 37 lines). – Sameer Nov 25 '14 at 14:19
  • rpt.Load("e:\\users\\shahid sultan minhas\\documents\\visual studio 2013\\Projects\\CystalReportsApp\\CystalReportsApp\\CrystalReport1.rpt"); – Sameer Nov 25 '14 at 14:35
  • Pardon me Sir but as i had mentioned earlier that i am working with Windows form application. Si how can a server come here. Moreover, database i am using is MS Access. – Sameer Nov 25 '14 at 14:36

7 Answers7

3

Try :

Web

 rpt.Load(Server.MapPath("\\CystalReportsApp\\CrystalReport1.rpt"))

Windows

rpt.Load(@"e:\\users\\shahid sultan minhas\\documents\\visual studio 2013\\Projects\\CystalReportsApp\\CystalReportsApp\\CrystalReport1.rpt")
Abdulrahman_88
  • 545
  • 1
  • 5
  • 15
  • Sir Should Windows form application be using Server? – Sameer Nov 25 '14 at 14:41
  • Sir there is no such path like yours in my system having no folders called TA_Virdi and Reports and no report with a name CryrepAttendanceReport.rpt. Please provide a valid answer if you have. Thanks – Sameer Nov 25 '14 at 15:36
  • Why must I use an absolute path? That is a terrible design. – Spero Jun 17 '19 at 12:48
1

Your problem (like mine) may still be related to the path to the RPT file. In an .aspx Web Form, you might benefit from this syntax:

    <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
        <Report FileName="~/MyCrystalReport.rpt">
        </Report>
    </CR:CrystalReportSource>

By using a relative path, I was able to execute my report files after many hours of trial-and-error.

0
MySql.Data.MySqlClient.MySqlDataAdapter myAdapter1 = new MySql.Data.MySqlClient.MySqlDataAdapter(ds.Tables[0].Rows[0]["Query"].ToString(), conn);
                    myAdapter1.Fill(myData);
                    WaitSumCrystalReport3 myr = new WaitSumCrystalReport3();
                    myr.SetDataSource(myData);
                    if (myData.Tables[0].Rows.Count > 0)
                        myr.PrintToPrinter(1, true, 1, 10);
                    cmd.CommandText = "Update tbl_print set Status='1' where ID='" + ds.Tables[0].Rows[0]["ID"].ToString() + "'";
                cmd.Connection = conn;
                cmd.ExecuteNonQuery();
//disposing the crystal report object to clear the temp memroy.. otherwise memory is overflow occurs in future
                    myr.Dispose();
//above statement is used to dispose... it will work fine

..

Lrrr
  • 4,755
  • 5
  • 41
  • 63
Shavas
  • 1
  • 1
    please provide some explanation – Lrrr Dec 13 '14 at 07:26
  • Thanks Sir for your concern but now i moved on and took a step forward. I have discarded Crystal Report because no way it worked. So i thought to use alternatives(simple but yet functional) and the best alternative i could find is Reportmax by cpp. Its wonderful to work with. And i would recommend everyone to give it a try once. – Sameer Dec 13 '14 at 15:16
0

cryRpt.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CrystalReport1.rpt"));

and right click on CrystalReport1.rpt goto properties and set the Build Action to Content and CopyOutputDirectory to Copy if newer..

hope it will help u, thanx

Sushil
  • 1
0

make sure that all your fields are populating properly.

Once I faced this kind of problem, which resolved after removing error in sql query

0

I use Procmon.exe with filters works fine to me (Access Denied to some folder):

https://stackoverflow.com/a/41942720/1536197

Community
  • 1
  • 1
Hernaldo Gonzalez
  • 1,977
  • 1
  • 21
  • 32
0

In my case, I first got an error: Could not load file or assembly 'CrystalDecisions.ReportAppServer.ClientDoc', Version=xxx'. And then I find and add reference to the xxx version of CrystalDecisions.ReportAppServer.ClientDoc.dll, then run the program, a new error Load Report Failed occur.

After asking my colleague, I goto Project > Properties > Build, and uncheck the Prefer 32-bit checkbox, and restore to use the original version I use of CrystalDecisions.ReportAppServer.ClientDoc.dll, then I can successfully generate report.

Besides I have installed 64-bit version of Crystal Reports runtime engine.

For ASP.NET Web Project, goto

 Tools
  -> Options
   -> Projects and Solutions
    -> Web Projects
     -> Check "Use the 64 bit version of IIS Express for web sites and projects"`

Reference: How can I force IIS Express to run in 32 bit mode?

yu yang Jian
  • 6,680
  • 7
  • 55
  • 80