Crystal Report is unable to open connection

32 Views Asked by At

Hey there I'm tring to view a crystal report WinForms .net framework 4.8 applicaion. Ive tried DSN and Server Name in connection info to ReportDocument but same error is thrown, I'm using 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;
    }

even with this code or reportDocument.SetDatabaseLogon(user: "myUser", password: "myPass", server: ServerName, database: MainDbName, ignoreCase: true); is the same error

1

There are 1 best solutions below

0
MilletSoftware On

Perhaps you have a mismatch between the app 64-bit or 32-bit) and the ODBC DSN (64-bit or 32-bit).

Also, what ODBC driver and what Crystal Runtime version are you using? Not all drivers are compatible with all runtime versions.