0
votes

I have a C# .NET WinForms application that uses Crystal Reports. Crystal reports run fine on both x32 and x64 systems with the exception of reports containing subreports. Any report containing a subreport fails with the wonderful: "Log on failed" at ...VerifyDatabase() but only on x64 systems.

I have seen and fixed this problem in the past by unchecking Verify Database on every print, making sure the no data is being saved with the report and ensuring the correct driver and connection methods are being used in the designer. This problem is not going away and seems to only be affecting reports with subreports.

All projects in the solution are set to build to x32. The x64 systems have the CR 32bit runtime installed. The SQL Native Client is also installed.

I have tried many different combinations of report preparations steps like not verifying the database, not refreshing the report, verifying and not refreshing, refreshing and not verifying... it goes on and on.

Here is the current preparation method being used:

    private T GetReport<T>() where T: ReportDocument, new()
    {
        var report = new T();

        var connectionStringBuilder
            = new SqlConnectionStringBuilder(this.ConnectionString);

        var connectionInfo = new ConnectionInfo
                                 {
                                     DatabaseName = connectionStringBuilder.InitialCatalog,
                                     UserID = connectionStringBuilder.UserID,
                                     Password = connectionStringBuilder.Password,
                                     ServerName = connectionStringBuilder.DataSource
                                 };

        Action<ReportDocument, bool, bool> setConnection = (document, verify, refresh) =>
            {
                document.DataSourceConnections.Clear();

                document.DataSourceConnections[0].SetConnection(
                    connectionStringBuilder.DataSource,
                    connectionStringBuilder.InitialCatalog,
                    connectionStringBuilder.UserID,
                    connectionStringBuilder.Password
                    );

                document.DataSourceConnections[0].IntegratedSecurity = false;

                /*
                foreach (Table table in document.Database.Tables)
                {
                    var tableLogOnInfo = table.LogOnInfo;
                    tableLogOnInfo.ConnectionInfo = connectionInfo;
                    table.ApplyLogOnInfo(tableLogOnInfo);
                }
                 * */

                //document.SetDatabaseLogon(connectionInfo.UserID, connectionInfo.Password, connectionInfo.ServerName, connectionInfo.DatabaseName);

                if (verify)
                    document.VerifyDatabase();

                if (refresh)
                    document.Refresh();
            };

        for (var index = 0; index < report.Subreports.Count; index++)
        {
            var subreportName = report.Subreports[index].Name;
            var subreport = report.OpenSubreport(subreportName);

            setConnection(subreport, false, false);
        }

        setConnection(report, true, true);

        return report;
    }

SOLVED: I have gotten the report to work. I am not sure what part of this solution actually solved the problem but these are the steps I took.

  1. I checked the data source per aMazing's suggestion below. (It was already OLE DB)
  2. I removed all referenced to Crystal Reports in all projects in the solution.
  3. I re-added the Crystal Reports references and made sure all the references were the same version and made sure all references were set to 'Specific Version' = True.
  4. I set 'Copy Local' to True on the CR references on one project in the solution.
  5. I changed the call to the **setConnection** to not verify.
  6. I un-commented foreach table.ApplyLogOnInfo(tableLogOnInfo) section.

I'm not sure why it works now but it does. The table.ApplyLogOnInfo was un-commented in many of the permutations I tried earlier. Maybe I never hit this specific combination... but I don't care at this point.

4

4 Answers

0
votes

Because I couldnt add a comment, this was the only way I could reply.

What SQL server are you using? I had something similar before.

Check the following on both report and sub report: 1) Right Click Datasource Properties 2) Select Set Datasource Location 3) On the connetion that the report is using, click expand Properties 4) Confirm that the Database Type = OLE DB (ADO) and Provider is SQLOLEDB.

That fixed my problem. I had set it to SQLNative Client before which was failing.

Hope it helps.

Thanks

0
votes

Check if you have an Access database or any other 32 bit datasource in any of the subreports.

0
votes

SOLVED: I have gotten the report to work. I am not sure what part of this solution actually solved the problem but these are the steps I took.

  1. I checked the data source per aMazing's suggestion below. (It was already OLE DB)
  2. I removed all referenced to Crystal Reports in all projects in the solution.
  3. I re-added the Crystal Reports references and made sure all the references were the same version and made sure all references were set to 'Specific Version' = True.
  4. I set 'Copy Local' to True on the CR references on one project in the solution.
  5. I changed the call to the **setConnection** to not verify.
  6. I un-commented foreach table.ApplyLogOnInfo(tableLogOnInfo) section.

I'm not sure why it works now but it does. The table.ApplyLogOnInfo was un-commented in many of the permutations I tried earlier. Maybe I never hit this specific combination... but I don't care at this point.

0
votes

I had this same problem recently. I found the cause to be not setting the datasource, which in my case was due to an incorrect if statement, meaning the following line was not running:

repdoc.Subreports["SubReportName.rpt"].SetDataSource((DataTable)MyDataTable);

Hope this is of use.