2012-12-17 155 views
0

我正嘗試將水晶報表導出爲PDF。下面的代碼(顯然密碼和服務器名稱之類的東西已被更改,以保護無辜)...無法獲取水晶報表導出

public void RunReport(string outputFile, int cc, int yr, int wk) 
{  
    ReportDocument rd = new ReportDocument();  
    rd.Load(FullFilePath("myreport.rpt"));  
    rd.Refresh();  
    rd.SetDatabaseLogon("userid", "password");  
    foreach (Table tbl in rd.Database.Tables)  
    {   
     tbl.LogOnInfo.ConnectionInfo.ServerName = "dbname";   
     tbl.LogOnInfo.ConnectionInfo.DatabaseName = "";   
     tbl.LogOnInfo.ConnectionInfo.UserID = "userid";   
     tbl.LogOnInfo.ConnectionInfo.Password = "password";  
    }  
    foreach (IConnectionInfo ci in rd.DataSourceConnections)  
    {   
     ci.SetLogon("userid", "password");  
    }  
    DiskFileDestinationOptions diskFileDestinationOptions = new DiskFileDestinationOptions();  
    ExportOptions exportOptions;  
    PdfRtfWordFormatOptions pdfFormatOptions = new PdfRtfWordFormatOptions();  
    diskFileDestinationOptions.DiskFileName = outputFile;  
    crExportOptions = rd.ExportOptions;  
    {   
     crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;   
     crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;   
     crExportOptions.DestinationOptions = diskFileDestinationOptions;   
     crExportOptions.FormatOptions = pdfFormatOptions;  
    }  

    SetCurrentValuesForParameterField(rd, "IP_COMP_CODE", cc);  
    SetCurrentValuesForParameterField(rd, "IP_YEAR", yr);  
    SetCurrentValuesForParameterField(rd, "IP_WEEK", wk);   

    rd.Export(); 
} 

private void SetCurrentValuesForParameterField(ReportDocument reportDocument, string paramFieldName, int value) 
{ 
    ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue(); 
    parameterDiscreteValue.Value = value.ToString(); 
    ParameterValues currentParameterValues = new ParameterValues(); 
    currentParameterValues.Add(parameterDiscreteValue); 
    reportDocument.DataDefinition.ParameterFields[paramFieldName].ApplyCurrentValues(currentParameterValues); 
} 

現在怪異的一部分,當我第一次寫這個代碼(以及它在SVN),它會給我一個COM異常,說它第一次執行導出(這是在ASP.NET MVC應用程序中)時內存不足,但所有後續導出(直到我重新啓動Web應用程序)才能正常工作。

錯誤產生的是:

First-chance exception at 0x75a2c41f in w3wp.exe: Microsoft C++ exception: _com_error at memory location 0x20dee4b0. 

A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in CrystalDecisions.CrystalReports.Engine.dll 

An exception of type 'System.Runtime.InteropServices.COMException' occurred in CrystalDecisions.CrystalReports.Engine.dll but was not handled in user code 

Additional information: Memory full. 

Failed to export the report.  

我張貼在SAP的網站和他們的支持的人提供的,我包括了一些更改代碼,然後將其完全停止,錯誤如下工作:

An exception of type 'CrystalDecisions.CrystalReports.Engine.DataSourceException' occurred in CrystalDecisions.ReportAppServer.DataSetConversion.dll but was not handled in user code 

Additional information: Failed to load database information. 
Error in File myreport {6DC42165-A38A-4CB2-85FD-A77389827FA9}.rpt: 

Failed to load database information.  

當我恢復代碼更改時,它繼續給我這個錯誤(並且從此)。現在我根本無法導出報告。

的變化他建議導致了這樣的代碼:

ReportDocument rd = new ReportDocument();  
rd.Load(FullFilePath("myreport.rpt"));  
ConnectionInfo connectInfo = new ConnectionInfo()  
{   
    ServerName = "dbname",   
    DatabaseName = "",   
    UserID = "userid",   
    Password = "password"  
};  
rd.SetDatabaseLogon("userid", "password");  

foreach (Table tbl in rd.Database.Tables)  
{   
    tbl.LogOnInfo.ConnectionInfo = connectInfo;   
    tbl.ApplyLogOnInfo(tbl.LogOnInfo);  
} 

現在SAP是說他們不會支持我,因爲我用VS.NET 2012年,即使我沒有使用任何VS. NET集成,簡單的SDK。他們已經非常無益。

我在Windows 7 64位上運行。我已經安裝的Crystal Reports SDK是:CRforVS_redist_install_64bit_13_0_4.zip,可從他們的網站獲得。

後端數據庫是Oracle,客戶端是11g。

我卸載並重新安裝了Oracle客戶端和Crystal Reports,但都沒有成功。我根本無法再導出報告。

回答

4

我最終不得不做所有事情爲32位。我永遠無法得到64位水晶工作。由於可怕的(粗魯的)技術支持,我們將轉儲Crystal用於SSRS。