Crystal报表,为什么它要求数据库登录即使我提供的信息?(Crystal reports, wh

2019-06-26 07:01发布

我生成一个报告,但问题是,即使我提供的凭据,当含有CrystalReport形式打开了,但它仍然要求我为他们,而最糟糕的是,我没有在那里输入任何东西,和公正单击完成,它加载的报告。 所以,如果没有必要的凭证(或其他)它为什么问我?

下面的代码

    private void MainReport_Load(object sender, EventArgs e)
    {
        var constr = string.Empty;
        constr = Application.StartupPath;
        if (Generate.bForProjects)
            constr = Path.Combine(constr, @"Reports\Projects.rpt");
        else
            constr = Path.Combine(constr, @"Reports\Other.rpt");

        var myConInfo = new CrystalDecisions.Shared.TableLogOnInfo();
        reportDocument1.Load(constr);
        myConInfo.ConnectionInfo.DatabaseName = "ProjectData.mdb";
        myConInfo.ConnectionInfo.ServerName = Application.StartupPath + @"\Data\ProjectData.mdb";
        myConInfo.ConnectionInfo.Password = "";
        myConInfo.ConnectionInfo.UserID = "";
        reportDocument1.Database.Tables[0].ApplyLogOnInfo(myConInfo);

        reportDocument1.Refresh();

        crystalReportViewer1.ReportSource = reportDocument1;
        crystalReportViewer1.Width = this.Width - 50;
        crystalReportViewer1.Height = this.Height - 100;
    }

加载窗体时,此屏幕弹出窗口

而且,当这来了,我不输入任何内容! 那就对了! 我只是点击完成,它完全加载报告! 所以,如果它没有什么需要,为什么HEL *是问我要登录?

Answer 1:

我们有很多的问题,当我们来到了一个水晶报表连接到不同的数据库到一个它的设计/针对创建。 我们结束了创建以下功能正确设置它。 它递归将所有报告表和子报表的连接。

此外,我好像记得,我们有问题,如果该报告的设计采用集成Windows身份验证,并用一个简单的用户名和密码运行。 所以,我们总能确保我们在设计报告用一个简单的用户名和密码连接到数据库。

private static void SetConnection(ReportDocument report, string databaseName, string serverName, string userName, string password)
{
    foreach (Table table in report.Database.Tables)
    {
        if (table.Name != "Command")
        {
            SetTableConnectionInfo(table, databaseName, serverName, userName, password);
        }
    }

    foreach (ReportObject obj in report.ReportDefinition.ReportObjects)
    {
        if (obj.Kind != ReportObjectKind.SubreportObject)
        {
            return;
        }

        var subReport = (SubreportObject)obj;
        var subReportDocument = report.OpenSubreport(subReport.SubreportName);
        SetConnection(subReportDocument, databaseName, serverName, userName,  password);
    }
}

private static void SetTableConnectionInfo(Table table, string databaseName, string serverName, string userName, string password)
{
    // Get the ConnectionInfo Object.
    var logOnInfo = table.LogOnInfo;
    var connectionInfo = logOnInfo.ConnectionInfo;

    // Set the Connection parameters.
    connectionInfo.DatabaseName = databaseName;
    connectionInfo.ServerName = serverName;
    connectionInfo.Password = password;
    connectionInfo.UserID = userName;
    table.ApplyLogOnInfo(logOnInfo);

    if (!table.TestConnectivity())
    {
        throw new ApplicationException(Resource.UnableToConnectCrystalReportToDatabase);
    }

    table.Location = Database + "." + "dbo" + "." + table.Location;
}


Answer 2:

它只有当你的数据集或数据表是空的出现。 所以一定要确保它的数据。



Answer 3:

只需创建报表对象,并添加以下链接rptobj是crystalreport对象,setdatabaselogin是方法,采取用户ID和密码作为参数。

rptobj.setdatabaselogon(userid,password)



文章来源: Crystal reports, why is it asking for database login even after I provided the details?