Crystal Report 无法打开连接

问题描述 投票:0回答:1

嘿,我正在尝试查看水晶报表 WinForms .net Framework 4.8 应用程序。我已尝试在 ReportDocument 的连接信息中使用 DSN 和服务器名称,但会引发相同的错误,我正在使用 SQL Server 2019 Express Edition。

    ReportDocument SetReportLogIn(ReportDocument reportDocument, string MainDbName, string ServerName, string SQLUserName, string SQLPassword)
    {
        ConnectionInfo ci = new()
        {
            ServerName = ServerName,
            DatabaseName = MainDbName,
            UserID = SQLUserName,
            Password = SQLPassword,
            IntegratedSecurity = false,
            Type = ConnectionInfoType.SQL,
        };

        TableLogOnInfo logonInfo;
        foreach (Table table in reportDocument.Database.Tables)
        {
            logonInfo = table.LogOnInfo;
            logonInfo.ConnectionInfo.ServerName = ci.ServerName;
            logonInfo.ConnectionInfo.DatabaseName = ci.DatabaseName;
            logonInfo.ConnectionInfo.UserID = ci.UserID;
            logonInfo.ConnectionInfo.Password = ci.Password;
            logonInfo.ConnectionInfo.Type = ci.Type;
            logonInfo.TableName = table.Name;

            logonInfo.ConnectionInfo.IntegratedSecurity = ci.IntegratedSecurity;
            table.ApplyLogOnInfo(logonInfo);
        }

        foreach (ReportDocument SubRpt in reportDocument.Subreports)
        {
            TableLogOnInfo SubLogonInfo;
            foreach (Table table in reportDocument.Database.Tables)
            {
                SubLogonInfo = table.LogOnInfo;
                SubLogonInfo.ConnectionInfo.ServerName = ci.ServerName;
                SubLogonInfo.ConnectionInfo.DatabaseName = ci.DatabaseName;
                SubLogonInfo.ConnectionInfo.UserID = ci.UserID;
                SubLogonInfo.ConnectionInfo.Password = ci.Password;
                SubLogonInfo.ConnectionInfo.IntegratedSecurity = ci.IntegratedSecurity;
                SubLogonInfo.ConnectionInfo.Type = ci.Type;
                SubLogonInfo.TableName = table.Name;
                table.ApplyLogOnInfo(SubLogonInfo);
            }
        }
        //        reportDocument.VerifyDatabase();

        return reportDocument;
    }

即使使用此代码或

reportDocument.SetDatabaseLogon(user: "myUser", password: "myPass", server: ServerName, database: MainDbName, ignoreCase: true);
也是相同的错误

winforms crystal-reports .net-4.8
1个回答
0
投票

也许您的应用程序(64 位或 32 位)与 ODBC DSN(64 位或 32 位)不匹配。

此外,您使用的 ODBC 驱动程序和 Crystal Runtime 版本是什么?并非所有驱动程序都与所有运行时版本兼容。

© www.soinside.com 2019 - 2024. All rights reserved.