• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3436
  • Last Modified:

Failed to load report error message using crystal report .net and c# 2005

Hi,

I have the following code that opens a crystal report and displays it in the viewer on the winform: -

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace Slimming
{
    public partial class frmProgressReport : Form
    {
        protected CrystalDecisions.CrystalReports.Engine.ReportDocument reportDocument1;

        public frmProgressReport()
        {
            InitializeComponent();
        }

        private void frmProgressReport_Load(object sender, EventArgs e)
        {
            lblUser.Text = Program.frmMain.cmbUsers.Text;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            fraBuilding.Visible = true;
            dsMeasurements myDSMeasurements = new dsMeasurements();
            //Create connection to mdf sql file
            System.Data.SqlClient.SqlConnection con2 =
                new System.Data.SqlClient.SqlConnection(
                @"Data Source=.\sqlexpress;AttachDbFilename=|DataDirectory|\MainDB.mdf;Integrated Security=True;User Instance=True");

            //Create new data adapter and perform query
            System.Data.SqlClient.SqlDataAdapter da2 = new System.Data.SqlClient.SqlDataAdapter("SELECT     m.UserID, m.Weight, m.DateTaken, ISNULL(m.Weight - p.Weight, 0) AS 'Gain / Loss' FROM Measurements AS m LEFT OUTER JOIN Measurements AS p ON p.UserID = m.UserID AND p.DateTaken = (SELECT MAX(DateTaken) AS Expr1 FROM Measurements AS mm WHERE (DateTaken < m.DateTaken)) WHERE (m.UserID = '" + globalclass.userID.ToString() + "') ORDER BY m.DateTaken DESC", con2.ConnectionString);

            // place result into fixed dataset
            da2.Fill(myDSMeasurements, "dtMeasurements");

            String path = Environment.CurrentDirectory;

            //show crystal report and bind dataset to report
            ReportDocument rpt = new ReportDocument();
            rpt.Load(@"H:\crtest.rpt");
            rpt.SetDataSource(myDSMeasurements.Tables["dtMeasurements"]);
            crystalReportViewer1.ReportSource = rpt;


        }
    }
}

When I click button1 it comes up with the error message on the line rpt.Load(@"H:\crtest.rpt"); : -



System.Exception was unhandled
  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 Slimming.frmProgressReport.button1_Click(Object sender, EventArgs e) in H:\Documents and Settings\Administrator\Desktop\Slimming3\frmProgressReport.cs:line 46
       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(Int32 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 Slimming.Program.Main() in H:\Documents and Settings\Administrator\Desktop\Slimming3\Program.cs:line 24
       at System.AppDomain._nExecuteAssembly(Assembly 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.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()



what am I doing wrong please.

Many Thanks
Lee
0
ljhodgett
Asked:
ljhodgett
  • 3
  • 2
1 Solution
 
MIKESoftware Solutions ConsultantCommented:
What "error" are you getting...???

MIkeV
0
 
ljhodgettAuthor Commented:
Hi Mike,

It just comes up with the error message:

System.Exception was unhandled
  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 Slimming.frmProgressReport.button1_Click(Object sender, EventArgs e) in H:\Documents and Settings\Administrator\Desktop\Slimming3\frmProgressReport.cs:line 46
       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(Int32 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 Slimming.Program.Main() in H:\Documents and Settings\Administrator\Desktop\Slimming3\Program.cs:line 24
       at System.AppDomain._nExecuteAssembly(Assembly 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.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()




When it gets to the line  rpt.Load(@"H:\crtest.rpt");. It doesn't actually say anything else. Is there a way to get more detail?

Best Regards
Lee
0
 
mlmccCommented:
Is this on the development machine or a client?

What is the @ for in the Load function?

mlmcc
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
ljhodgettAuthor Commented:
Its on the development machine. Sorry I'm new to c#. I seemed to needed the @ at the begining otherwise it would come up with the error message: -

Error      1      Unrecognized escape sequence

Best Regards
Lee
0
 
ljhodgettAuthor Commented:
Hi,

I've just tried it on another development pc and it works correctly but not on my main development pc. Has anyone got a clue why?

Best Regards
Lee
0
 
mlmccCommented:
Check the differences in options in the compiler.

You might have to use \\ on your machine.

mlmcc
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now