To change a persistent data source

Persistent data sources provide data for a report that exists both within and beyond runtime scope. The recommended way to change your persistent data source is to use the com.crystaldecisions.sdk.occa.report.application.DatabaseController.replaceConnection method.
Each table used by a report requires a properly configured data source connection, represented by a IConnectionInfo object. The replaceConnection method automatically propagates your new data source connection to all tables in the report that use the old connection.
Note: If instead you want to change the connection for a particular table, you can do so using one of the setTableLocation methods available in the DatabaseController class.
The following steps show how to change a single data source connection for all tables in a report to a new XML and Web Services connection. However, the fundamental workflow described can be applied to any type of data source.
  1. Retrieve the DatabaseController object.
    DatabaseController databaseController = rcd.getDatabaseController();
  2. Retrieve the collection of all data source connections in the report.
    ConnectionInfos connectionInfos = databaseController.getConnectionInfos(null);
  3. Call the getConnectionInfo method of the ConnectionInfos collection to retrieve a single connection.

    Note: This example assumes the report has a single data source. Different tables in your report may have different data source connections, and you can change the connection for each in the collection as necessary.
    IConnectionInfo oldConnectionInfo = connectionInfos.getConnectionInfo(0);
  4. Create a new ConnectionInfo object to represent the new data source connection.
    IConnectionInfo newConnectionInfo = new ConnectionInfo();
    newConnectionInfo.setKind(ConnectionInfoKind.CRQE);
  5. Create a new PropertyBag object and add the custom logon properties specific to the new data source type.
    PropertyBag logonProperties = new PropertyBag();
    logonProperties.put("Http(s) XML URL", "C:\\customer.xml");
    logonProperties.put("Http(s) Schema URL", "C:\\customer.xsd");
    logonProperties.put("Convert Mulitivalue to Table", false);
  6. Create a new PropertyBag object and add the custom logon properties, as well as the default connection properties for the new data source.
    PropertyBag properties = new PropertyBag();
    properties.put(PropertyBagHelper.CONNINFO_CRQE_LOGONPROPERTIES, logonProperties);
    properties.put(PropertyBagHelper.CONNINFO_CRQE_SERVERDESCRIPTION, "Description");
    properties.put(PropertyBagHelper.CONNINFO_CRQE_SQLDB, false);
    properties.put(PropertyBagHelper.CONNINFO_CRQE_DATABASETYPE, "XML and Web Services");
    properties.put(PropertyBagHelper.CONNINFO_CRQE_DATABASENAME, "");
    properties.put(PropertyBagHelper.CONNINFO_SSO_ENABLED, false); 
    properties.put(PropertyBagHelper.CONNINFO_DATABASE_DLL, "crdb_xml.dll"); 
  7. Call the setAttributes method of the IConnectionInfo object to set the connection properties of the new data source.
    newConnectionInfo.setAttributes(properties);
  8. Set the user name and password credentials for the new data source.
    newConnectionInfo.setUserName("username");
    newConnectionInfo.setPassword("password");
  9. Call the replaceConnection method of the DatabaseController object to change your old data source connection to the new connection.
    databaseController.replaceConnection(oldConnectionInfo, newConnectionInfo, null, DBOptions._useDefault);
Example: 
The following code changes a single data source connection for all tables in a report to a new XML and Web Services connection.
void changePersistentDatasource(ReportClientDocument rcd) throws ReportSDKException, ReportSDKServerException
{
  DatabaseController databaseController = rcd.getDatabaseController();
  ConnectionInfos connectionInfos = databaseController.getConnectionInfos(null);
  IConnectionInfo oldConnectionInfo = connectionInfos.getConnectionInfo(0);
  IConnectionInfo newConnectionInfo = new ConnectionInfo();
        
  newConnectionInfo.setKind(ConnectionInfoKind.CRQE);
 
  PropertyBag logonProperties = new PropertyBag(); 
  logonProperties.put("Http(s) XML URL", "C:\\customer.xml");
  logonProperties.put("Http(s) Schema URL", "C:\\customer.xsd");
  logonProperties.put("Convert Mulitivalue to Table", false);
        
  PropertyBag properties = new PropertyBag();
  properties.put(PropertyBagHelper.CONNINFO_CRQE_LOGONPROPERTIES, logonProperties); 
  properties.put(PropertyBagHelper.CONNINFO_CRQE_SERVERDESCRIPTION, "A description - local XML files");
  properties.put(PropertyBagHelper.CONNINFO_CRQE_SQLDB, false);
  properties.put(PropertyBagHelper.CONNINFO_CRQE_DATABASETYPE, "XML and Web Services");
  properties.put(PropertyBagHelper.CONNINFO_CRQE_DATABASENAME, "");
  properties.put(PropertyBagHelper.CONNINFO_SSO_ENABLED, false); 
  properties.put(PropertyBagHelper.CONNINFO_DATABASE_DLL, "crdb_xml.dll");
        
  newConnectionInfo.setAttributes(properties);
  newConnectionInfo.setUserName("username");
  newConnectionInfo.setPassword("password");
  
  databaseController.replaceConnection(oldConnectionInfo, newConnectionInfo, null, DBOptions._useDefault);   
}
This list includes the classes used by the sample code:
  • com.crystaldecisions.sdk.occa.report.application.DatabaseController
  • com.crystaldecisions.sdk.occa.report.application.DBOptions
  • com.crystaldecisions.sdk.occa.report.application.ReportClientDocument
  • com.crystaldecisions.sdk.occa.report.data.ConnectionInfo
  • com.crystaldecisions.sdk.occa.report.data.ConnectionInfos
  • com.crystaldecisions.sdk.occa.report.data.IConnectionInfo
  • com.crystaldecisions.sdk.occa.report.data.ConnectionInfoKind
  • com.crystaldecisions.sdk.occa.report.lib.PropertyBag
  • com.crystaldecisions.sdk.occa.report.lib.PropertyBagHelper
  • com.crystaldecisions.sdk.occa.report.lib.ReportSDKException
  • com.crystaldecisions.sdk.occa.report.lib.ReportSDKServerException