Crystal Reports 13 с динамическим параметром на основе команды, использующей IBM DB2 - PullRequest
0 голосов
/ 17 мая 2019

У меня есть отчет crsytal с динамическим параметром, основанным на команде.Когда я пытаюсь изменить базовое соединение с базой данных, оно работает только с ORACLE, но не с IBM DB2.

. Он выдает исключение CrystalDecisions.CrystalReports.Engine.LogOnException с ошибкой входа в систему и никакой дополнительной информации при вызове VerifyDatabase () метод.

Все отлично работает с ORACLE или с параметрами, которые являются статическими или основаны на таблице (вместо команды).

private readonly ConnectionInfo _connectionInfo = new ConnectionInfo();

...

private void ConfigureCrystalReports()
{
    _connectionInfo.Type = ConnectionInfoType.CRQE;
    _connectionInfo.ServerName = _dbName;
    _connectionInfo.UserID = _userId;
    _connectionInfo.Password = _password;

    PropertyBag connectionAttributes = new PropertyBag();

    connectionAttributes.EnsureCapacity(3);
    connectionAttributes.Add("Server", _dbName);
    connectionAttributes.Add("Trusted_Connection", false);
    connectionAttributes.Add("Owner", _userId);

    _connectionInfo.Attributes.Collection.Add(new NameValuePair2("Database DLL", "crdb_db2cli.dll"));
    _connectionInfo.Attributes.Collection.Add(new NameValuePair2("QE_DatabaseName", ""));
    _connectionInfo.Attributes.Collection.Add(new NameValuePair2("QE_LogonProperties", connectionAttributes));
    _connectionInfo.Attributes.Collection.Add(new NameValuePair2("QE_ServerDescription", _dbName));
    _connectionInfo.Attributes.Collection.Add(new NameValuePair2("QE_SQLDB", true));
    _connectionInfo.Attributes.Collection.Add(new NameValuePair2("SSO Enabled", false));
    _connectionInfo.Attributes.Collection.Add(new NameValuePair2("Owner", _userId));
}

...

private void SetDBLogonForReport(ReportDocument reportDocument)
{
    PropertyBag boMainPropertyBag = new PropertyBag();

    PropertyBag boInnerPropertyBag = new PropertyBag();

    boInnerPropertyBag.Add("Server", _dbName);
    boInnerPropertyBag.Add("Trusted_Connection", "False");

    boMainPropertyBag.Add("Database DLL", "crdb_db2cli.dll");
    boMainPropertyBag.Add("QE_DatabaseName", "");
    boMainPropertyBag.Add("QE_DatabaseType", "");

    boMainPropertyBag.Add("QE_LogonProperties", boInnerPropertyBag);
    boMainPropertyBag.Add("QE_ServerDescription", _connectionInfo.ServerName);
    boMainPropertyBag.Add("QE_SQLDB", "False");
    boMainPropertyBag.Add("SSO Enabled", "False");

    CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo boConnectionInfo = new CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo();

    boConnectionInfo.Attributes = boMainPropertyBag;

    boConnectionInfo.Kind = CrConnectionInfoKindEnum.crConnectionInfoKindCRQE;
    boConnectionInfo.UserName = _connectionInfo.UserID;
    boConnectionInfo.Password = _connectionInfo.Password;

    CrystalDecisions.ReportAppServer.DataDefModel.Tables tables = reportDocument.ReportClientDocument.DatabaseController.Database.Tables;

    foreach (InternalConnectionInfo internalConnectionInfo in reportDocument.DataSourceConnections)
    {
        internalConnectionInfo.SetConnection(_connectionInfo.ServerName, _connectionInfo.DatabaseName,_connectionInfo.UserID, _connectionInfo.Password);
    }

    foreach (CrystalDecisions.ReportAppServer.DataDefModel.Table table in tables)
    {
        dynamic d = table;
        if (table.ClassName == "CrystalReports.CommandTable")
        {
            switch (_dbTyp)
            {
                case "DB2":
                    // does not work
                    CommandTable newCommandTable = new CommandTable { ConnectionInfo = boConnectionInfo, Name = table.Name, CommandText = Regex.Replace(d.CommandText, @"RVADMIN\.", _qualifier, RegexOptions.IgnoreCase) };
                    reportDocument.ReportClientDocument.DatabaseController.SetTableLocation(table, newCommandTable);

                    // does not work
                    table.ConnectionInfo.Attributes["QE_DatabaseName"] = _connectionInfo.DatabaseName;
                    table.ConnectionInfo.Attributes["QE_ServerDescription"] = "XXX";
                    table.ConnectionInfo.Attributes["QE_LogonProperties"]["Database"] = _connectionInfo.DatabaseName;
                    table.ConnectionInfo.UserName = boConnectionInfo.UserName;
                    table.ConnectionInfo.Password = boConnectionInfo.Password;

                    // does not work
                    table.ConnectionInfo = boConnectionInfo;
                    d.CommandText = Regex.Replace(d.CommandText, @"XXX\.", _qualifier, RegexOptions.IgnoreCase);
                    break;

                    // EDIT 2019-05-17
                    // works just fine
                    reportDocument.SetSQLCommandTable(_connectionInfo, table.Name, Regex.Replace(d.CommandText, @"XXX\.", _qualifier, RegexOptions.IgnoreCase));
                case "ORA":
                    // works just fine
                    table.ConnectionInfo = boConnectionInfo;
                    d.CommandText = Regex.Replace(d.CommandText, @"XXX\.", _qualifier, RegexOptions.IgnoreCase);
                    break;
            }
        }
        else
        {
            // ...
        }
    }

    reportDocument.VerifyDatabase(); // throws CrystalDecisions.CrystalReports.Engine.LogOnException with "logon failed" and no further information
}

...

crystalReportViewer.ReportSource = ReportDoc

Есть идеи?

Большое спасибо.

...