Tuesday, February 10, 2009

Crystal Reports java viewer JNDI problem

I hate Crystal Reports. We use CR XI and it really sucks. Crystal Reports java library has some awful bugs.

When report viewer is loading there's some output to stdout:
Crystal Report Viewer 11.8.4.1197
java.vendor = Sun Microsystems Inc.
java.version = 1.6.0_10
os.name = Windows XP
os.version = 5.1
os.arch = x86

Why? Because inside CR classes there's a direct output to std out and it sucks. But it's a minor problem.

The worst bug is inside database connection layer, somewhere very deep inside CR java lib. Under an unknown condition sometimes it throws some exceptions with "error finding JNDI name" message. It happens while "switching database". If you don't know what's this, try to dig the net.

The problem is that the reason cannot be defined. The same report sometimes causes this error to appear while another invocation causes nothing bad to happen and the report displays properly.

Workaround

Did I mentioned that Crystal Reports sucks? Oh, yes. As I wrote repeating invocation of a report causes it to display properly. So after two days of debugging and digging throught the Internet with no solution I came to stupid but successful idea.  Repeat tables switching until no error appears. The process doesn't take too long. It always took only two loops to successful switch. SWITCH_TABLE_RETRIES is limit of tries (mine is set to 3 and it works well).
boolean successSwitch = false;
//Update old table in the report with the new table.
for (int j = 0; j < SWITCH_TABLE_RETRIES; j++) {
if (successSwitch) {
if (j > 1 && Logger.getLogger(AbstractReport.class).isDebugEnabled()) {
Logger.getLogger(AbstractReport.class).debug("Switch tables after tries: " + j);
}
break ;
}

try {
databaseController.setTableLocation(t, tables.getTable(i));
successSwitch = true;
} catch (final Throwable th) {
//if it's the last try as we failed
if (j + 1 == SWITCH_TABLE_RETRIES) {
Logger.getLogger(AbstractReport.class).error("Switch tables error " + th.getMessage());
}
}
}

There's another bug discovered by some guy and another weird solution.

CR sux :) The end.

And some polish phrases to be indexed by google and help my colleagues to solve the problem.

Błąd podczas znajdowania nazwy JNDI
Problem z Crystal Reports XI
Przeglądarka
Błąd wyświetlania raportu, raportów

1 comment:

  1. Hey, if you're up for it, we'd love to hear your feedback on our Java-based reporting product, i-net Crystal-Clear 10 (http://www.inetsoftware.de/products/crystalclear). Our customers seem to be pretty happy with us - we have quite a few that have successfully migrated from Crystal Reports.

    Don't want to bore you with marketing stuff, but here are a couple of summarized points to hopefully pique your interest:

    * Able to read Crystal Reports templates so that they wouldn't have to be re-designed.
    * Simple JDBC-based data source management
    * Comes with its own report designer and report server with web interface and ad-hoc reporting module.
    * Powerful and well-designed API

    ReplyDelete