i am trying to open a crystal report in my website but its giving an error Here is the code i have tried

 protected void report_view(object sender, EventArgs e)
   {
    ReportDocument cryRpt = new ReportDocument();
    TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
    TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
    ConnectionInfo crConnectionInfo = new ConnectionInfo();
    Tables CrTables;

    cryRpt.Load("C:\\Report1.rpt");

    crConnectionInfo.ServerName = "local";
    crConnectionInfo.DatabaseName = "MyEmployees";
    crConnectionInfo.UserID = "MYLAPTOP\\HOME";

    CrTables = cryRpt.Database.Tables;
    foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
    {
        crtableLogoninfo = CrTable.LogOnInfo;
        crtableLogoninfo.ConnectionInfo = crConnectionInfo;
        CrTable.ApplyLogOnInfo(crtableLogoninfo);
    }

    CrystalReportViewer1.ReportSource = cryRpt;
    CrystalReportViewer1.RefreshReport();
    }

and here is the error shown in CrystalReportViwer

  Failed to open the connection. Failed to open the connection. Report1 {1222DD0B-C24E-  4E66-8EE1-7ED7F5F0D6B4}.rpt

i am using visual studio 2010 with Crystal Reports 11

有帮助吗?

解决方案

It seems that you are missing a password when declaring the connection details. Try adding it:

crConnectionInfo.ServerName = "local";
crConnectionInfo.DatabaseName = "MyEmployees";
crConnectionInfo.UserID = "MYLAPTOP\\HOME";
crConnectionInfo.Password = "Password"; //Swap with real password of course

Ensure that all file paths and file names are also correct.

Alternatively you can look into the SetDataBaseLogon() method

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top