Improving Crystal Reports Performance

March 18, 2007

If we need to set the database logon info at runtime, i.e, changing Server name, Database name, User Id or Password we need to implement some code similar to:

ConnectionInfo connectionInfo = new ConnectionInfo();
TableLogOnInfo tableLogonInfo = new TableLogOnInfo();

connectionInfo.ServerName = “myServer”;
connectionInfo.DatabaseName = “myDatabase”;
connectionInfo.UserID = “user”;
connectionInfo.Password = “password”;

Tables tables = reportDocument.Database.Tables;

foreach (Table table in tables)
{
 tableLogonInfo = table.LogOnInfo;
        tableLogonInfo.ConnectionInfo = connectionInfo;
        table.ApplyLogOnInfo(tableLogonInfo);
}

In Crystal Reports XI, if the original connection info differs from the current settings, this process happens to be very time consuming and directly proportional with the number of tables in the report!

We can dramatically improve the response time of the printing requests from the second invocation of the report. To do so we just save the report after setting the connection info for each table:

reportDocument.SaveAs(reportDocument.FileName);

Now the subsequent calls to this report will be much faster because the Crystal Engine verifies that we are not changing the logon info.


VS 2005 and Crystal Reports headakes

March 16, 2007

This week I was involved in a project where we needed to implement a small reporting mechanism. As we are using Visual Studio 2005 and Crystal Reports was handy, since it was tightly integrated, we decided to implement some reports with it. Everything went prety fine until the moment of setting the report logon info at runtime. The headakes started.

From my experience i have come to the following conclusions:

  1. If you create a database connection with Integrated Security, no matter what you do, you will never able to switch, at runtime, to SQL Security.
  2. You cannot change the initial server and database name, as well as the user id and password.

Since I could not find any suitable workaround for this problems, I have decided to install the Crystal Reports XI full product and implement a new report from scratch.

Happily everything works fine now, or at least I hope so.

This behavior is absolutly unaceptable in a develoment tool such as the MS Visual Studio 2005. I let this tips for you guys hopping that you don’t spare your precious time.