Skip to Content

Requesting Clarification about DatabaseController.ReplaceConnection Method

I'm seeking a clarification about the DatabaseController.ReplaceConnection() method, when used with the CrDBOptionsEnum.crDBOptionDoNotVerifyDB.

Q1. When does this method require access to the database driver?

Q2. When does this method require (or attempt) access to the data source?

In general, is there a text description of how this method goes about executing its logic?

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    Posted on Feb 28, 2019 at 03:51 PM

    Hi Ido,

    It depends on what is mapped in the report and what is in the new connection info in the steps the DB mapping gets triggered which is affected by the old/new data info.

    It's not something that is a simple explanation, all depends on the DB From/To.

    As noted we don't have any info published on how it all works since it's been this way for years.

    Don

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 27, 2019 at 06:38 PM

    Hi Ido,

    It basically alters the connection property bag and adds the "QE...." to the connection info.

    You can see examples from the KBA: ( use Google to search for this )

    1553921 - Is there a utility that would help in writing database logon code?

    It doesn't actually make the connection until the SetLocation API is called.

    Here's a sample to update the connection for a Command Object and update the SQL:

    static void testSetSQLCommandTable_CRPE(CrystalDecisions.CrystalReports.Engine.ReportDocument rpt)
    {
        CrystalDecisions.ReportAppServer.Controllers.DatabaseController databaseController = rpt.ReportClientDocument.DatabaseController;
        CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfos connectionInfos = databaseController.GetConnectionInfos(null);
        CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo oldConnectionInfo = connectionInfos[0];
        CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo newConnectionInfo = CreateConnectionInfo();
        databaseController.ReplaceConnection(oldConnectionInfo, newConnectionInfo, null, CrDBOptionsEnum.crDBOptionMapFieldByRowsetPosition);
    
        ISCRTable oldTable = (ISCRTable)databaseController.Database.Tables[0];
        CommandTable newTable = new CommandTable();
        newTable.Alias = "Command";
        newTable.Name = "Command";
        newTable.QualifiedName = "Command";
        newTable.ConnectionInfo = newConnectionInfo;
        newTable.CommandText = @" SELECT 'Customer'.'Contact Last Name'  FROM 'xtreme'.'dbo'.'Customer' 'Customer'";
        //newTable.CommandText = @"SELECT 'Checks'.'CheckID', 'Checks'.'LoopType', 'Checks'.'RunType' FROM 'astellastest'.'dbo'.'Checks' 'Checks' WHERE 'Checks'.'CheckID'<100";
    
        databaseController.SetTableLocation(oldTable, newTable);
    }

    And remember if any fields are not in the SQL that the Reprot expects, has saved in the RPT file, the auto-field mapping routine will simply remove it from the report.

    We don't have any documentation on how this API works internally.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 27, 2019 at 08:08 PM

    Thanks Don.
    You state above that "It doesn't actually make the connection until the SetLocation API is called."
    However, my experience is that the ReplaceConnection() Method does require access to either the driver or the database even when my code does NOT call SetTableLocation().
    What I'm looking for is: under what conditions does this method do that.
    Does it always need access to the driver?
    Does it sometimes need access to the actual data source? If so, what are those conditions?

    I understand if that answer is: sorry, we don't know and DEV doesn't have the time to investigate.
    I just want to make sure it is understood I am NOT asking about the SetTableLocation() method.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.