尝试导出为 pdf 时出现 InvalidComObjectException 错误。我认为这可能与连接到 oracle 有关,但不确定。SetDatabaseLogon 似乎偏爱 Sql Server。该报告调用数据的存储过程,并使用 Business Objects XIR2 服务工作。我也可以查看报告并在设计器内部进行连接。
'CrystalDecisions.CrystalReports.Engine 13.0.2000.0' .NET Framework 4.0 的水晶报告
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportAppServer.DataDefModel
Imports CrystalDecisions.Shared
Imports CrystalDecisions.ReportSource
Public Overloads Function CreateReport(ByVal reportFileName As String, ByVal reportTitle As String, ByVal outputDirectory As String, _
ByVal isFullPath As Boolean, ByVal outputFormat As OutputFormat, ByVal crystalParameter As CrystalParameter) As String
Dim baseReportsSourcePath As String = "C:\ADSTAX\SUITES\RFL\Letters\"
Dim baseReportsOutputPath As String = "C:\PDF_Exports\"
Dim fullFilepath As String = baseReportsSourcePath + reportFileName
'check report exists
If File.Exists(fullFilepath) = False Then Throw New FileNotFoundException("File:" + fullFilepath + " does not exist", fullFilepath)
Dim doc As ReportDocument = New ReportDocument()
doc.Load(fullFilepath)
'set parameters
If crystalParameter.Name = CrystalParameterName.DistributionKey Then
doc.SetParameterValue("DISTRIBUTIONKEY", crystalParameter.Value)
ElseIf crystalParameter.Name = CrystalParameterName.RequestKey Then
doc.SetParameterValue("REQUESTKEY", crystalParameter.Value)
End If
'user, pass, server, database
doc.SetDatabaseLogon("user", "pass")
'build full output filename
Dim exportFileName As String = Path.GetFileNameWithoutExtension(reportFileName)
exportFileName += Guid.NewGuid.ToString + ".pdf"
Dim fullOuputFilePath As String = baseReportsOutputPath + exportFileName
'export to pdf
doc.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, fullOuputFilePath)
'check report created
If File.Exists(fullFilepath) = False Then
Return String.Empty
End If
Return fullOuputFilePath
End Function
下面的错误:
System.Runtime.InteropServices.InvalidComObjectException was unhandled
Message=COM object that has been separated from its underlying RCW cannot be used.
Source=mscorlib
StackTrace:
at System.StubHelpers.StubHelpers.StubRegisterRCW(Object pThis, IntPtr pThread)
at System.Runtime.InteropServices.ComTypes.IConnectionPoint.Unadvise(Int32 dwCookie)
at CrystalDecisions.ReportAppServer.ISCDClientDocumentEvents_EventProvider.RemoveOnClosed(_ISCDClientDocumentEvents_OnClosedEventHandler handler)
at CrystalDecisions.ReportAppServer.ISCDClientDocumentEvents_EventProvider.remove_OnClosed(_ISCDClientDocumentEvents_OnClosedEventHandler value)
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.DisconnectEventRelay()
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.InternalClose(Boolean bSetupForNextReport, Boolean bAutoClose)
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.Dispose(Boolean bDisposeManaged)
at System.ComponentModel.Component.Dispose()
at CrystalDecisions.CrystalReports.Engine.ReportDocument.ClearCache(Boolean clearDocument)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.InternalClose(Boolean bSetupForNextReport)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.Close()
at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExitHandler(Object sender, EventArgs e)
InnerException: