INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

SQL Connection Issues when Programmatically running Crystal in vb.net

SQL Connection Issues when Programmatically running Crystal in vb.net

(OP)
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

RE: SQL Connection Issues when Programmatically running Crystal in vb.net

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close