troubleshooting Question

Crystal Reports Datasource Question

Avatar of Bob_Stan
Bob_Stan asked on
Crystal ReportsProgrammingVisual Basic.NET
20 Comments1 Solution441 ViewsLast Modified:
I have some old Crystal 10 reports I am trying to display in VS2010.  They work fine, until I need to run them on a SQL Server/Database different than the one on which they are created.  I have seen all the code and am using something like shown below.  It appears that the code is not actually making any changes although NO exception is raised.  For example if i trace through the code on my development machine aTable.location will be "Customer" and when I run it, it will change to "MyDatabase.dbo.Customer".  But if the original location is a different Server and or database, the aTable location remains "Customer" and when the viewer attempts to display the report, I get a viewer error stating the connection, server, database, user, and password are empty.  I am using integrated security so I shouldn't need user or password.  Any help appreciated.
crReport.Load(_reportName) 

Dim crDatabase As Database = crReport.Database
Dim crTables As Tables = crDatabase.Tables
Dim crConnectionInfo As ConnectionInfo = ChangeConnection()
Dim crTableLogOnInfo As New TableLogOnInfo
Dim strLocation As String

For Each aTable In crTables
   crTableLogOnInfo = aTable.LogOnInfo
   crTableLogOnInfo.ConnectionInfo.ServerName = crConnectionInfo.ServerName
   crTableLogOnInfo.ConnectionInfo.DatabaseName = crConnectionInfo.DatabaseName
   aTable.ApplyLogOnInfo(crTableLogOnInfo)
   strLocation = String.Format("{0}.dbo.{1}", crConnectionInfo.DatabaseName, aTable.Location.Substring(aTable.Location.LastIndexOf(".") + 1))
   Try
     aTable.Location = strLocation
   Catch ex As Exception
     'exception code here
   End Try
Next


Private Shared Function ChangeConnection() As ConnectionInfo
Dim objconnectioninfo As ConnectionInfo = New ConnectionInfo
      
objconnectioninfo.IntegratedSecurity = True
objconnectioninfo.ServerName = "MyServer"
objconnectioninfo.DatabaseName = "MyDatabase"
Return objconnectioninfo

Open in new window

ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 20 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 20 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros