• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 411
  • Last Modified:

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

A while back someone asked a question about changing the database in a Crystal Report (http://www.experts-exchange.com/Databases/Crystal_Reports/Q_21516382.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

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,

  • 3
1 Solution
Look at these examples.  I believe there is one that changes the database connection


workinclassjoeAuthor Commented:
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?

workinclassjoeAuthor Commented:

Ok, I think I got it.

As best I can tell, in order to properly change the data source in VB code for a Crystal Report with a SQLOLEDB connection to a SQL Server database, you must acquire access/initialize the connection parameters it uses, not just the ConnectionInfo (if at all necessary).  This can only be done through an instantiated connection control (SQLConnection, OleDBConnection, etc.), where you would change the ConnectionString's "Initial Catalog" and "Integrated Security" parameters.

I believe that's what the previously mentioned document, http://www.experts-exchange.com/Databases/Crystal_Reports/Q_21516382.html, was leading to.  Business Objects has created the COM object CRAXDRT for the very purpose of exposing the parameters of a ConnectionString property for data source initialization (possibly more to it than that; never used this class before).  As far as I can tell, however, it, like it's connection control counterpart, is used to establish a connection and datasource for a dataset or recordset, neither of which I use.  Each report ties directly to a view or stored procedure on my database, so I have no need for a dataset.  Thus, I think the idea of modifying the datasource on the fly is a mute point.

I'll leave this thread open a while for more feedback should anyone have any.


workinclassjoeAuthor Commented:
Sorry, I'm using EE QuickPost.  I didn't want this question deleted, just closed.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now