I've been all around the developers' forums on this problem. Hopefully someone has a solution.
1. I'v running VS 2010 programming in VB.NET
2. I have a crystal report that I need to export to PDF.
3. I keep getting the error "Failed to open the connection" at the point where I call the crReportDocument.ExportToDisk function.
4. Here is my object creation and load:
crReportDocument = New ReportDocument()
crReportDocument.Load ( strRPT_FullFilename )
5. Here is my connection string (strConnectionString): Data Source=DB_SERVER;Initial Catalog=DB_NAME;Integrated Security=True;Pooling=True;Connect Timeout=30;
6. In order to correctly populate the Crystal ConnectionInfo object, I'm doing the following:
arrConnectionStringParts = strConnectionString.Split ( ";" )
For x As Integer = 0 to arrConnectionStringParts.length-1
Dim arrParts As String()
arrParts = arrConnectionStringParts(x).Split ( "=" )
If arrParts(0) = "Data Source" then strServerName = arrParts(1)
If arrParts(0) = "Initial Catalog" then strDatabase = arrParts(1)
Next
'***** log on to SQL server
Dim objConnectionInfo As New ConnectionInfo
With objConnectionInfo
.Type = ConnectionInfoType.SQL
.IntegratedSecurity = True
.ServerName = strServerName
.DatabaseName = strDatabase
End With
Dim objTables As Tables = crReportDocument.Database.Tables
' The report's dataset is generated by a Command that makes use of two tables, both of which get their connection info from the "For Each objTable..." below
For Each objTable As CrystalDecisions.CrystalReports.Engine.Table In objTables
Dim objTableLogonInfo As TableLogOnInfo = objTable.LogOnInfo
objTableLogonInfo.ConnectionInfo = objConnectionInfo
objTable.ApplyLogOnInfo ( objTableLogonInfo )
Next
7. All of that seems to be working. I'm not getting any exception errors. (I have a try catch surrounding all of the code)
8. However, executing this line: crReportDocument.ExportToDisk ( ExportFormatType.PortableDocFormat, strPDF_FullFilename )
results in an exception:
Does anyone know what I need to do?
Thanks in advance,
Jerry Scannell
1. I'v running VS 2010 programming in VB.NET
2. I have a crystal report that I need to export to PDF.
3. I keep getting the error "Failed to open the connection" at the point where I call the crReportDocument.ExportToDisk function.
4. Here is my object creation and load:
crReportDocument = New ReportDocument()
crReportDocument.Load ( strRPT_FullFilename )
5. Here is my connection string (strConnectionString): Data Source=DB_SERVER;Initial Catalog=DB_NAME;Integrated Security=True;Pooling=True;Connect Timeout=30;
6. In order to correctly populate the Crystal ConnectionInfo object, I'm doing the following:
arrConnectionStringParts = strConnectionString.Split ( ";" )
For x As Integer = 0 to arrConnectionStringParts.length-1
Dim arrParts As String()
arrParts = arrConnectionStringParts(x).Split ( "=" )
If arrParts(0) = "Data Source" then strServerName = arrParts(1)
If arrParts(0) = "Initial Catalog" then strDatabase = arrParts(1)
Next
'***** log on to SQL server
Dim objConnectionInfo As New ConnectionInfo
With objConnectionInfo
.Type = ConnectionInfoType.SQL
.IntegratedSecurity = True
.ServerName = strServerName
.DatabaseName = strDatabase
End With
Dim objTables As Tables = crReportDocument.Database.Tables
' The report's dataset is generated by a Command that makes use of two tables, both of which get their connection info from the "For Each objTable..." below
For Each objTable As CrystalDecisions.CrystalReports.Engine.Table In objTables
Dim objTableLogonInfo As TableLogOnInfo = objTable.LogOnInfo
objTableLogonInfo.ConnectionInfo = objConnectionInfo
objTable.ApplyLogOnInfo ( objTableLogonInfo )
Next
7. All of that seems to be working. I'm not getting any exception errors. (I have a try catch surrounding all of the code)
8. However, executing this line: crReportDocument.ExportToDisk ( ExportFormatType.PortableDocFormat, strPDF_FullFilename )
results in an exception:
Does anyone know what I need to do?
Thanks in advance,
Jerry Scannell