在ASP.NET中打开Crystal报表时出错

时间:2013-10-28 05:54:18

标签: crystal-reports crystal-reports-xi

我正在尝试在我的网站上打开一个水晶报告,但它给出了一个错误 这是我试过的代码

 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();
    }

,这是CrystalReportViwer中显示的错误

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

我正在使用带有Crystal Reports 11的visual studio 2010

1 个答案:

答案 0 :(得分:1)

在声明连接详细信息时,您似乎缺少密码。尝试添加它:

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

确保所有文件路径和文件名也正确无误。

或者,您可以查看SetDataBaseLogon() method