Crystal reports 创建项目设置后Crystal报告不工作

Crystal reports 创建项目设置后Crystal报告不工作,crystal-reports,report,project,installation,Crystal Reports,Report,Project,Installation,我已经为我的Windows项目创建了一些Crystal报告。当我在VisualStudio上运行它们时,它们运行良好。(我正在使用VS2010)。但是,在我创建安装项目并在客户端PC上安装软件后,它们将无法工作。我收到以下错误: 下面显示的是我用来加载crystal报表的按钮单击事件代码:第一个try子句用于向报表注册自定义输入,同时第二个try子句用于手动创建与报表的数据库连接。第三个try子句仅用于加载报表 private void buttonGenerateSecExportRpt_C

我已经为我的Windows项目创建了一些Crystal报告。当我在VisualStudio上运行它们时,它们运行良好。(我正在使用VS2010)。但是,在我创建安装项目并在客户端PC上安装软件后,它们将无法工作。我收到以下错误:

下面显示的是我用来加载crystal报表的按钮单击事件代码:第一个try子句用于向报表注册自定义输入,同时第二个try子句用于手动创建与报表的数据库连接。第三个try子句仅用于加载报表

private void buttonGenerateSecExportRpt_Click(object sender, EventArgs e)
    {
        CrystalDecisions.CrystalReports.Engine.ReportDocument cryRpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
        if (comboBoxSecPlateType.Text != "" && comboBoxSecExPlateBrand.Text != "")
        {
            try
            {
                dtFrom.Format = DateTimePickerFormat.Custom;
                string periodfrom = dtFrom.Value.ToString("yyyy/MM/dd");
                dtTo.Format = DateTimePickerFormat.Custom;
                string periodto = dtTo.Value.ToString("yyyy/MM/dd");

                //cryRpt.VerifyDatabase();
                string fullPath = "..\\..\\SecondaryPlateExportReport.rpt";
                cryRpt.Load(fullPath);
                cryRpt.SetParameterValue("dateFromChecked", dtFrom.Checked);
                cryRpt.SetParameterValue("dateToChecked", dtTo.Checked);
                cryRpt.SetParameterValue("dtPeriodFrom", periodfrom);
                cryRpt.SetParameterValue("dtPeriodTo", periodto);
                cryRpt.SetParameterValue("PlateType", comboBoxSecPlateType.Text.Trim());
                cryRpt.SetParameterValue("PlateBrand", comboBoxSecExPlateBrand.Text.Trim());

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            try
            {
                DbConnectionInfo.SetConnectionString(ConfigurationManager.ConnectionStrings["con"].ToString());
                TableLogOnInfo logOnInfo;
                ConnectionInfo connectionInfo;
                foreach (Table table in cryRpt.Database.Tables)
                {
                    logOnInfo = table.LogOnInfo;
                    connectionInfo = logOnInfo.ConnectionInfo;
                    // Set the Connection parameters.
                    connectionInfo.DatabaseName = DbConnectionInfo.InitialCatalog;
                    connectionInfo.ServerName = DbConnectionInfo.ServerName;
                    if (!DbConnectionInfo.UseIntegratedSecurity)
                    {
                        connectionInfo.Password = DbConnectionInfo.Password;
                        connectionInfo.UserID = DbConnectionInfo.UserName;
                    }
                    else
                    {
                        connectionInfo.IntegratedSecurity = true;
                    }
                    table.ApplyLogOnInfo(logOnInfo);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            try
            {
                crystalReportViewerSecEx.ReportSource = cryRpt;
                crystalReportViewerSecEx.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        else
        {
            MessageBox.Show("Please select both Plate Type and the Brand to Generate the Report!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
我想让水晶报告工作后,部署在客户端PC上的软件。任何建议将不胜感激

Shehan

最好不要在任何.NET项目中使用硬编码路径。最好使用Server.MapPath变量并动态生成字符串

例如,将using System.IO添加到项目中。然后可以使用Path.Combine方法生成字符串

    string mappath = HttpContext.Current.Server.MapPath("~/");
    Path.Combine(mappath, "Report Folder Path", "FileName.rpt");
您甚至可以将“报表文件夹路径”放入静态字符串中,这样就可以多次调用它,而无需担心更改

crystalReport.Load(@"C:\WINDOWS\Temp\samridhi.rpt");
创建安装程序时,请将水晶报告路径如下

转到“C:\WINDOWS\Temp”

并将您的rpt和.cs文件复制到“C:\WINDOWS\Temp”,由mycomputer而不是运行提示符执行


对于不设置,仅检查项目应用程序中的crystal report path

路径是

  crystalReport.Load(System.Windows.Forms.Application.StartupPath + "\\samridhi.rpt");