Click here to Skip to main content
15,795,331 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm a new member. My English is poor!
Why is this code Load Report Failed error?
Thank you.

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

namespace WindowsFormsApplication2
    public partial class Form1 : Form
        public Form1()
        private void SetLogin(ConnectionInfo connectioninfo,ReportDocument reportdocument)
            TableLogOnInfos TbLogOnInfos = crystalReportViewer1.LogOnInfo;
            foreach (TableLogOnInfo TbLogOnInfo in TbLogOnInfos)
                TbLogOnInfo.ConnectionInfo = connectioninfo;
            Tables tables = reportdocument.Database.Tables;
            foreach (Table table in tables)
                TableLogOnInfo tbllogoninfo = table.LogOnInfo;
                tbllogoninfo.ConnectionInfo = connectioninfo;
        private void Form1_Load(object sender, EventArgs e)
            ReportDocument RepDoc = new ReportDocument();
            ConnectionInfo connectioninfo = new ConnectionInfo();
            connectioninfo.ServerName = "(local)";
            connectioninfo.Password = "123";
            connectioninfo.UserID = "sa";
            connectioninfo.DatabaseName = "Gold_Database";
            string RepPach = Application.StartupPath + @"\WindowsFormsApplication2\CrystalReport2.rpt";
            crystalReportViewer1.ReportSource = RepPach; // ---------Invalid report file path ERROR
            crystalReportViewer1.ReportSource = RepDoc;
            SetLogin(connectioninfo, RepDoc);           

CHeck that the crystal resides at the given path.
You can debug through the code, put a break point on string RepPach = Application.StartupPath + @"\WindowsFormsApplication2\CrystalReport2.rpt";, and then read the file path here.
Check if the file exists at that path.
Share this answer
Application.StartupPath = "G:\WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug"
//Crystal in this direction is

//RepPach of the break point is NULL

//With this command gives error
string RepPach = Application.StartupPath + @"..\..\CrystalReport2.rpt";

--Please help me.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900