I'm trying to export my crystal report to pdf but keep getting the "failed to open a connection" error. It seems as if the error is happening at the CR.Export line. I've tried everything but don't know how to fix it. FYI, it's working on my development server, but when I copy it to the production server, I get the error. So it's very hard to pin point where it's occurring.
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
Try
InitializeComponent()
strPermitNo = Session("RecordID")
SpWithViewer(strPermitNo)
CrystalReportViewer2.DataBind()
Catch er As Exception
LogError(er.ToString, "PageInit-PrintPermit1.aspx")
Exit Try
Finally
End Try
End Sub
` Protected Sub btnExport_Click(sender As Object, e As EventArgs) Handles btnExport.Click
strPermitNo = Session("RecordID")
Try
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
CrDiskFileDestinationOptions.DiskFileName = "\\idsfmsrvr\wwwroot\FWPDFs\" & strPermitNo & ".pdf"
strAttachment = "\\idsfmsrvr\wwwroot\FWPDFs\" & strPermitNo & ".pdf"
Session("Attachment") = strAttachment
CrExportOptions = CR.ExportOptions
If True Then
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions
CrExportOptions.FormatOptions = CrFormatTypeOptions
End If
CR.Export()
EmailPermitToApplicant()
File.Delete(strAttachment)
lblMsg.Text = "Permit has been emailed to applicant."
lblMsg.Visible = True
Catch er As Exception
LogError(er.ToString, "btnExport()-PrintPermit1.aspx")
Exit Try
Finally
connFTS.Close()
End Try`
Just a step:
- Open a report first, follow this link
- Export it whatever you want.
Take note: you can hide the form if you don't want to display the report.
Good Luck!