I get an InvalidComObjectException error when trying to export to pdf. I think it might have something to do with connecting to oracle, but not sure. The SetDatabaseLogon seem to favor Sql Server. The report calls a stored proc for the data, and is working using the Business Objects XIR2 service. I can view the report and connect inside the designer also.
'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
Error Below:
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: