0

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

 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

4

1 回答 1

1

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

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

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

或者,您可以查看SetDataBaseLogon() 方法

于 2013-10-28T06:02:20.313 回答