Skip to Content
avatar image
Former Member

Can I edit the rpt file & change the datasource before loading the report?

We are an ISV and our application has a lot of reports. Our reports use a SQL Server database as the data source and each SQL Server at our customer sites has a different name.

In our testing we have determined that ReportDocument.Load tries to connect to the SQL Server that is saved in the RPT. If it can't fine the SQL Server saved in the RPT the load take about 60 seconds while it is waiting for the SQL Server Connection to time out.

We are using the Visual Studio 2008 version of Crystal Reports. This did not seem to be a problem with VB6/CR8.5.

We would like to edit the RPT and change the data source to the appropriate SQL Server before we call ReportDocument.Load.

Is it possible to edit the rpt file and change the data source before loading the report?

Or is there some way to tell Crystal not to try connecting to the DB

during the report.load?

In our case we will NEVER use the data source that is saved in the RPT, we will always change the data source using ApplyLogOnInfo.


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Jul 15, 2008 at 07:04 PM

    HI Todd,

    You Can Not edit the report document before ReportDocument.Load() because if you dont load the report then you dont have anything to Edit 😊

    But as far as changing the datasource is concerned you can change that at runtime.

    For changing the datasource following code will help you if both databases have a same schema :

    Code for changing the database

    ConnectionInfo crConnectionInfo = new ConnectionInfo();

    crConnectionInfo.ServerName = "SERVER";

    crConnectionInfo.DatabaseName = "DATABASE";

    crConnectionInfo.UserID = "USERID";

    crConnectionInfo.Password = "PASSWORD";

    // Loop through the ReportObjects in a report and find all the subreports

    foreach(ReportObject crReportObject in crReportDocument.ReportDefinition.ReportObjects)


    // Check the kind of the ReportObject, if it is a subreport

    // proceed. If not skip.

    if(crReportObject.Kind == ReportObjectKind.SubreportObject)


    // Get the SubReport in the form of a ReportDocument

    string sSubreportName = ((SubreportObject)crReportObject).SubreportName;

    ReportDocument crSubReportDocument = crReportDocument.OpenSubreport(sSubreportName);

    // Use a loop to go through all the tables in the main report

    foreach(Table crTable in crSubReportDocument.Database.Tables)


    // Get the TableLogOnInfo from the Table and then set the new

    // ConnectionInfo values.

    TableLogOnInfo crLogOnInfo = crTable.LogOnInfo;

    crLogOnInfo.ConnectionInfo = crConnectionInfo;

    // Apply the TableLogOnInfo


    // Set the location of the database. This value will vary from database to

    // database.

    crTable.Location = "DATABASE.OWNER.TABLENAME" or crTable.Locations;




    The sample for doing this is available on support site.



    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Ludek Uher

      Has anyone worked this one out?

      We are also an ISV who ship and application bundled with hundreds of Crystal Reports. When then load, they are trying to connect to the development database.

      Unfortunately, you have to load the report before you can change its connection string to the production database?

      This is madness!

      Using CR2008

      Any ideas?


  • avatar image
    Former Member
    Jul 15, 2008 at 07:35 PM

    Hi ,

    One way to fasten the loading of report is adding the load method in Pre-Init Event of life cycle.



    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 15, 2008 at 07:47 PM

    Hi Todd,

    By Adding ReportDoc.Load() method to Pre-Init event, I mean Pre-Init Event of .Net Page in case of .Net Web application.

    There is no document available for this.

    This is just a testing what i have done at my end .



    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Ludek Uher

      Thanks Ludek.

      Unfortunately CR 12 has not fixed my problem. Here are the things I tried.

      I installed CR 12 on a different machine, open the rpt with CR 12 and saved the rpt in the CR12 format. (The rpt would originally created in CR 8.5.) The rpt still took over a minute to load because it was trying to connect to a DB Server that it could not see.

      I installed CR 12 on my development machine, upgraded my references to use the CR 12 assemblies and still have the problem.

      Here is an easy way for anyone to reproduce this behavior:

      1. Create a simple report pointing to a SQL Server DB (your SQL Server will need to be on a machine separate from the machine you are running CR on).

      2. Turn off the SQL Server Machine.

      3. Try to click on the Database menu in CR. It will take about a minute to dropdown. This is because CR is looking for the database machine but cannot find it.

      One interesting note: CR is just looking for the machine. It is not looking for SQL, the DB, or the table used in the report. To verify this you can restart the SQL Machine but leave SQL Server stopped.

      At this point the only "work around" that I have been able to figure out is to load the rpt, change the LogOn info, and export the report as an rpt (replacing the original rpt). This will save the customers Data Source information in the rpt so that subsequent loads of the rpt will be quick.

      Any other ideas? It seems like there would be a lot of ISVs who run reports against SQL Server and embed Crystal in their applications. It seems like all of them would have this problem.