Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Connection Issues when Programmatically running Crystal in vb.net

Status
Not open for further replies.

JScannell

Programmer
Jan 9, 2001
306
US
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
 
As an addendum to my own post, if I comment out the ApplyLoginInfo for-next loop it works fine. It should be pointed out that the Crystal Report itself has connections to our developmet environment so that's why I can run it right out of the bos and it works. The problem will be when we run our app in test or prod then I have to get the ApplyLoginInfo loop to work correctly.


Jerry Scannell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top