在Windows 7 x64上带有Subreport的Crystal Report失败 [英] Crystal Report with Subreport failing on Windows 7 x64

查看:86
本文介绍了在Windows 7 x64上带有Subreport的Crystal Report失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Crystal Reports的C#.NET WinForms应用程序.除包含子报表的报表外,Crystal报表在x32和x64系统上均可正常运行.任何包含子报表的报告都会失败,并带有以下奇妙的效果:在... VerifyDatabase()处出现登录失败" ,但仅在x64系统上.

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.

解决方案中的所有项目均设置为x32.x64系统已安装CR 32位运行时.还安装了SQL Native Client.

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;
    }

已解决:我已经得到报告了.我不确定该解决方案的哪一部分可以真正解决问题,但这是我采取的步骤.

  1. 我按照下面aMazing的建议检查了数据源.(它已经是OLE DB)
  2. 我删除了解决方案中所有项目中所有对Crystal Reports的引用.
  3. 我重新添加了Crystal Reports参考,并确保所有参考均为相同版本,并确保所有参考均设置为特定版本" = True.
  4. 我在解决方案中一个项目的CR引用上将'Copy Local'设置为True.
  5. 我将呼叫更改为** setConnection **而不进行验证.
  6. 我未评论foreach表.ApplyLogOnInfo(tableLogOnInfo)部分.

我不确定为什么现在可以使用,但是可以使用.table.ApplyLogOnInfo在我之前尝试过的许多排列中均未注释.也许我从来没有碰到这种特定的组合...但是我现在不在乎.

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.

推荐答案

我最近也遇到了同样的问题.我发现原因未设置数据源,在我的情况下,这是由于错误的if语句所致,这意味着以下行未运行:

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);

希望这很有用.

这篇关于在Windows 7 x64上带有Subreport的Crystal Report失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆