创建项目设置后Crystal报表无法正常工作

时间:2012-08-08 17:33:36

标签: crystal-reports report project installation

我为Windows Project创建了一些Crystal Reports。我在Visual Studio上运行它们时运行正常。 (我正在使用VS 2010)。但是在我创建安装项目并在客户端PC上安装软件后,它们无法工作。我收到以下错误:

http://tistus.srilanka-erickson.com/errors.html

显示的是我用来加载水晶报告的按钮点击事件代码:第一个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上部署软件后使水晶报告工作。任何建议将不胜感激!

2 个答案:

答案 0 :(得分:2)

crystalReport.Load(@"C:\WINDOWS\Temp\samridhi.rpt");

当你创建设置时,将你的水晶报告路径设为这样

转到“ C:\ WINDOWS \ Temp

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


未设置只是为了检查项目应用程序中的晶体报告路径

路径是

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

答案 1 :(得分:0)

Shehan,

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

作为示例,将使用System.IO添加到项目中。然后,您可以使用Path.Combine方法来构建字符串。

    string mappath = HttpContext.Current.Server.MapPath("~/");
    Path.Combine(mappath, "Report Folder Path", "FileName.rpt");

您甚至可以将“报告文件夹路径”放入静态字符串中,以便可以多次调用它而不必担心更改。