Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOWTO: RDC - Compatibility with older reports 2

Status
Not open for further replies.

Bontebok

Programmer
Nov 18, 2002
63
US
Hi Everyone,

While developing Crystal Report viewing software using the Crystal Reports 9 RDC, I ran into some problems keeping the Crystal Reports 9 RDC compatible with previous versions of Crystal Reports, namely 8.5. I have learned since then that the problems I was experiencing were not bugs, but in fact very "undocumented features" that exist in the Crystal Reports 9 RDC.

Anyone developing an application that uses the Crystal Reports 9 RDC (and perhaps .NET RDC) that wishes to remain backwardly compatible to Crystal Reports version 8.5 (and possibly prior) should read this before they spend hours trying to figure out what is wrong.

-
In order to print, export, or view a Crystal Report file with a database, a connection must first be established to the database. Each table in the report contains a set of properties know as the "ConnectionProperties" bag, this is a collection object that stores name and value pairs appropriate for the type of connection for this database table.

These properties are stored inside of the Crystal Reports files and are passed to the database driver when the report is being rendered. The properties are different for each driver and the most common of properties can be found in the "Crystal Reports 9 Technical Reference Guide".

If you follow all of the documentation in the reference guide, you will have no problems reading or writing to each of the properties for a Crystal Reports 9 report file.

But what should happen if you follow the documentation for the Crystal Reports 9 RDC while loading a Crystal Report written in a previous version to 9? You may possibly receive the following error while trying to access a valid connection property.

Code:
Run-time error '-2147417848 (80010108)'

Automation Error 
The object invoked has disconnected from its clients.

This message is very unclear but it means that you are trying to access a connection property that does not exist. This error can come from either trying to read or write to a property.

Try it out!

1) Create two Crystal Reports files. One in a version prior to version 9 and the other in Crystal 9. Add one table to an Access database and place this data in the report.

2) Open up VB6 and start a new project.

3) Set a reference to the Crystal 9 RDC by selecting Project -> References -> and checking off "Crystal Reports 9 ActiveX Designer Run Time Library"

4) Paste and run the following code in the immediate window. Be sure to change the report file name to point to the Crystal version 9 report file.

Code:
Set CRXApp = Nothing: Set CRXRpt = Nothing
Set CRXApp = New CRAXDRT.Application
Set CRXRpt = CRXApp.OpenReport("c:\temp\access-9.rpt")
For Each A In CRXRpt.Database.Tables 1).ConnectionProperties: ?A.Name: Next

Output:

Code:
Database Name
Database Type
Database Password
Session UserID
Session Password
System Database Path

5) Clear the immediate window and paste and run the following code. Be sure to change the report file name to point to the older Crystal Report file.

Code:
Set CRXApp = Nothing: Set CRXRpt = Nothing
Set CRXApp = New CRAXDRT.Application
Set CRXRpt = CRXApp.OpenReport("c:\temp\access-8.rpt")
For Each A In CRXRpt.Database.Tables 1).ConnectionProperties: ?A.Name: Next

Output:

Code:
PreQEServerType
PreQEServerName
UserId
Data File

What is this PreQE stuff?! It's not referenced anywhere in the documentation and as of right now, you won't find it on Crystal Decision's website. Crystal Decision's has explained that the "PreQE" means "Pre-Query Engine", which means that this report was created in a version prior to Crystal 9.

These are the connection properties for connecting to an Access database in a Crystal Report written in a version of Crystal prior to 9. You will find that other database drivers will also have similar connection properties that are not in the technical reference guide.

How am I supposed to handle this? In my first attempt, I wrote an upgrade function that converted these properties into the new Crystal 9 properties. This worked great, but it was a lot of spaghetti code, but how could I be certain that I am covering all of the properties for every database driver?

As I added support that used the TestConnectivity function of the DatabaseTables object, I stumbled onto something by accident. After calling this method, all of the connection properties were now upgraded to the version 9 connection properties!

Try it out!

6) Clear the immediate window and paste and run the following code. Be sure to change the report file name to point to the older Crystal Report file.

Code:
Set CRXApp = Nothing: Set CRXRpt = Nothing
Set CRXApp = New CRAXDRT.Application
Set CRXRpt = CRXApp.OpenReport("c:\temp\access-8.rpt")
CRXRpt.Database.Tables(1).TestConnectivity
For Each A In CRXRpt.Database.Tables 1).ConnectionProperties: ?A.Name: Next

Output:

Code:
Database Name
Database Type
Database Password
Session UserID
Session Password
System Database Path

The results show that if you run TestConnectivity before querying or modifying the ConnectionProperties, the properties will be upgraded to the Crystal Report 9 connection properties!

So remember! To save yourself from headaches and wasted hours, run the TestConnectivity function before checking any connection properties. Besides, it is good practice to use the TestConnectivity function anyhow so you can determine if the DatabaseTable can be connected without requiring you to supply additional information (like a password or DSN).

Sincerely,

Jeremy Bair
Application Developer
jb at ungulate.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top