2012-08-08 35 views
0

我爲Windows項目創建了一些Crystal Reports。當我在Visual Studio上運行它們時,它們運行良好。 (我正在使用VS 2010)。但是,在我創建安裝項目並在客戶端PC上安裝軟件後,他們無法工作。我收到以下錯誤:創建項目設置後,Crystal報表無法正常工作

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

繼顯示的是我用來加載水晶報表按鈕點擊事件代碼:一是儘量條款已被用於定製輸入註冊報告,同時第二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上部署軟件後使Crystal Reports工作。任何建議將不勝感激!

回答

0

Shehan,

最好不要在任何.NET項目中使用硬編碼路徑。最好使用Server.MapPath變量並動態構建您的字符串。

作爲一個例子添加使用System.IO到您的項目。然後,您可以使用Path.Combine方法來構建您的字符串。

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

你甚至可以將「報告文件夾路徑」爲靜態的字符串,以便它可以被多次調用,而不必擔心改變。

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

當u創建設置把UR水晶報表路徑是這樣

去 「C:\ WINDOWS \ TEMP

和複製烏爾RPT和的.cs文件轉到「C:\ WINDOWS \ Temp」by mycomputer not by run prompt


不只是設置在這裏的項目應用程序來檢查水晶報表路徑是

路徑

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