Link to home
Start Free TrialLog in
Avatar of workinclassjoe
workinclassjoe

asked on

Changing database doesn't work - .NET and CR10 Solution

A while back someone asked a question about changing the database in a Crystal Report (https://www.experts-exchange.com/questions/21516382/Changing-database-doesn't-work.html).  Apparently, even if you've identified a different database in your data source, the report may still point to the old database due to something needing to be set for 'fully qualified table names'.  The solution given spoke to a work around in VB 6 using the CRAXDRT reference.

I'm using Crystal Reports 10 in VB .NET. My form class has Import references to CrystalDecisions.Shared and CrystalDecisions.CrystalReports.Engine, not CRAXDRT.  I use a ReportDocument object to set the Server and Database names depending on who's using the application.  I'm running into the same problem: even though I point to a different database, the data is returned from the database originally set.

Here's a sample of my code, most of which is pulled from the example given in the ApplyLogOnInfo help text (Visual Studio .NET):

                Dim logOnInfo As New TableLogOnInfo
                Dim connectionInfo As New ConnectionInfo
                For x = 0 To Me.multiReportDocument.Database.Tables.Count - 1
                    ' Get the ConnectionInfo Object.
                    logOnInfo = New TableLogOnInfo
                    logOnInfo = multiReportDocument.Database.Tables.Item(x).LogOnInfo

                    connectionInfo = New ConnectionInfo
                    connectionInfo = multiReportDocument.Database.Tables.Item(x).LogOnInfo.ConnectionInfo

                    ' Set the Connection parameters.
                    If database <> "" Then
                        connectionInfo.DatabaseName = database
                    End If
                    If server <> "" Then
                        connectionInfo.ServerName = server
                    End If
                    If password <> "" Then
                        connectionInfo.Password = password
                    End If
                    If user <> "" Then
                        connectionInfo.UserID = user
                    End If
                    multiReportDocument.Database.Tables.Item(x).ApplyLogOnInfo(logOnInfo)
                Next

I only specifiy the database and server names.  I didn't think I needed to set the user and password parms, even though I allow for them for future use, because of Windows Authentication (won't know the password for the individual user's anyway).

Anyone know what I might be missing?  Also, what exactly is the 'Overridden Qualified Table Name' property of the Set Datasource Location window as mentioned in the Q_21516382 document?  I'm using Crystal Reports 10 with a SQLOLEDB Provider connection as well and I have yet to see this property.

Thanks in advance,

Dave
Avatar of Mike McCracken
Mike McCracken

Look at these examples.  I believe there is one that changes the database connection

http://support.businessobjects.com/communityCS/FilesAndUpdates/vbnet_win_samples.exe.asp

mlmcc
Avatar of workinclassjoe

ASKER

New news:

This ain't a VB .NET issue at all!

I just made a duplicate copy of the same report, changed the database in the Set Datasource Location window in the new copy, and ran both the original and the dup stand-alone in Crystal Reports 10.

Guess what.  They both return the same data, even though the duplicate is pointing to an empty database.  Can someone please tell me what the heck is going on here?

Thanks for the reference to the samples, mlmcc, but based on this discovery, even with the proper VB code, if the report source malfunctions stand-alone it won't behave any differently in a report viewer.  'Course I've been wrong before.

Any ideas...anyone?

-Dave
ASKER CERTIFIED SOLUTION
Avatar of workinclassjoe
workinclassjoe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, I'm using EE QuickPost.  I didn't want this question deleted, just closed.