I can't get the Crystal 10 viewer to switch databases. I have some code below that worked with the CRAXDRT.dll library in Crystal 8.5. I commonly have to fire a crystal reports that are pointed at SQL servers and usually use either OLEDB or ODBC as it's connection. I am always having to test a crystal report agains a test database, and then copy this crystal report into a production environtment. Since the software we support moved to crystal 10 (yeah I know that was a while ago...) I haven't been able to get the craxdrt library to actually switch databases. It just continues to point at the database that was used to develope the crystal report.
Below is the boiled down VB 6.0 code I use:
Public pbReport As CRAXDRT.report
Public Sub RunReport(ByVal PnFileNameIN As String)
Dim report As New CRAXDRT.report
Dim crxApplication As New CRAXDRT.Application
Dim crxDatabase As CRAXDRT.Database
Dim crxDatabaseTable As CRAXDRT.DatabaseTable
Set report = crxApplication.OpenReport(PnFileNameIN, 1)
For Each crxDatabaseTable In report.Database.Tables
' FOR ODBC
crxDatabaseTable.SetLogOnInfo "ODBC datasource name", Database, "<<Use Integrated Security>>"
' FOR OLEDB
crxDatabaseTable.SetLogOnInfo server, Database, user, pwd
Set pbReport = report
' frmprint uses PBreport as it's reportsource