【问题标题】:Dynamic load .rpt in C#C#中的动态加载.rpt
【发布时间】:2017-01-28 08:11:42
【问题描述】:
try
{
     string spath = AppDomain.CurrentDomain.BaseDirectory;
     spath += "myReportFileName.rpt";

     ReportDocument cryRpt = new ReportDocument();
     cryRpt.Load(spath);

     cryRpt.DataSourceConnections[0].SetConnection("Server Name", "DB Name", true);
     cryRpt.DataSourceConnections[0].IntegratedSecurity = true;
     cryRpt.SetParameterValue("Field Name", "Value");
     cryRpt.RecordSelectionFormula = "Correct Formula";

     crystalReportViewer1.ReportSource = cryRpt;
     crystalReportViewer1.Refresh();
}
catch (System.Exception ex)
{
     MessageBox.Show("Error: " + ex.Message);
}

在我的系统中,这段代码是可以的。但在其他系统中,它有错误。我在所有其他系统中正确安装了水晶报告。

此代码执行时出错:

crystaldecisions.crystalreports.engine.reportdocument' 抛出异常

然后我在客户端系统中执行了 CRRuntime_32bit_13_0_3.msi。该错误解决了其他问题:

运行代码后,出现“数据库登录”对话框,我没有自动连接数据库,也没有查看报告文件!!!

请帮帮我,我该怎么办?

【问题讨论】:

  • 如果您使用集成安全性,则执行您的报告的用户需要拥有数据库权限。如果身份验证失败,则会向用户显示连接对话框以提供正确的凭据。您的代码中没有什么需要修复的。
  • 用户有权限,“数据库登录”对话框显示禁用数据库名称字段!!!然后使用无法设置数据库名称
  • 我的解决方案是什么? @rene
  • 我不知道。如果您确定凭据正常并且其他依赖项到位,我不知道。
  • @rene 还是谢谢你

标签: c# crystal-reports reportdocument


【解决方案1】:

我解决了我的问题。 :) 当我创建项目时,我的系统上安装了 CrystalReport 版本 10。因此,我从 Toolbox Item 中选择了“crystalReportViewer version 10”。 我卸载了水晶报表的10版并安装了11版。下一步,我从Visual Studio的工具箱中删除了水晶报告查看器,然后再次从工具箱项中选择了“水晶报告查看器版本11”。

现在我的项目和创建的 exe 文件,在所有具有晶体报告版本 10 的系统中都能正确执行。

谢谢! @rene :)

【讨论】:

    猜你喜欢
    • 2014-06-11
    • 2019-05-31
    • 2013-05-05
    • 1970-01-01
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多