views:

685

answers:

2

I have a crystal report which gives me undefined error when opening document, does any one come across this type of error, below is the coding:

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

        ///create instance of class first
        ReportDocument rpDoc = new ReportDocument();
        ///load the report
        rpDoc.Load(@"TicketingBasic.rpt");////------->>>problem is here

        ///pass the report to method for dataInfo
        getDBInfo(rpDoc);
        /// et the source for report to be displayed
        CrystalReportViewer1.ReportSource = rpDoc;
    }

    protected static void getDBInfo(ReportDocument rpDoc)
    {
        ///Connection Onject
        ConnectionInfo cn = new ConnectionInfo();
        ///DataBase,Table, and Table Logon Info
        Database db;
        Tables tbl;
        TableLogOnInfo tblLOI;

        ///Connection Declaration
        cn.ServerName = "???????????";
        cn.DatabaseName = "??????????";
        cn.UserID = "?????????";
        cn.Password = "????????????";

        //table info getting from report
        db = rpDoc.Database;
        tbl = db.Tables;

        ///for loop for all tables to be applied the connection info to
        foreach (Table table in tbl)
        {
            tblLOI = table.LogOnInfo;
            tblLOI.ConnectionInfo = cn;
            table.ApplyLogOnInfo(tblLOI);
            table.Location = "DBO." + table.Location.Substring(table.Location.LastIndexOf(".") + 1);

        }

        db.Dispose();
        tbl.Dispose();
    } 

}

Final code snippet is:

 rpDoc.Load(Server.MapPath(@"TicketingBasic.rpt"));

Thank you all for the help.

The problem I am having now is report not printing or exporting to other types like .pdf,.xsl, .doc etc, any clue

+1  A: 

How are you handling the report outout?

When we do reports we set the file name:

ReportSource.Report.FileName = FileName;

Where filename is a string that is the name of the file (obviously). Then we select the report tables and export in whatever format. Try this.

The Sheek Geek
exporting is not a problem, because it's inclided in report-->export to .pdf,.excel,.doc...., the problem I am having is opening the document
fzshah76
I understand that, it was just an example and idea for setting the report file a different way. Good Luck!
The Sheek Geek
+2  A: 

so the error is literally "undefined error"? never seen that one before.

First guess is that you need the full physical path to the report.

rpDoc.Load(Server.MapPath(@"TicketingBasic.rpt"));

HttpServerUtility.MapPath

dotjoe
The problem I am having now is report not printing or exporting to other types like .pdf,.xsl, .doc etc, any clue
fzshah76
What happens if you load the report in page_init?
dotjoe
+1 Man this kills me when the accepted answer doesn't get an upvote. Happened to me twice recently now.
Dusty