PDF にエクスポートしようとすると、InvalidComObjectException エラーが発生します。オラクルへの接続と関係があるのではないかと思いますが、よくわかりません。SetDatabaseLogon は Sql Server を支持しているようです。レポートは、データのストアド プロシージャを呼び出し、Business Objects XIR2 サービスを使用して動作しています。レポートを表示して、デザイナー内でも接続できます。
'CrystalDecisions.CrystalReports.Engine 13.0.2000.0 'Crystal Reports for .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: