Skip to Content
Former Member
Jan 09, 2012 at 07:54 PM

Crystal Server 2011 .NET RAS SDK ReplaceConnection method


We are replacing a .NET application that displayed non-embedded reports located on a local file directory with a .NET application that displays the same reports that are now located on Crystal Server 2011.

In the non-embedded reports application, the user could select the database (Development, QA, Production) that they wished to run the report with and the application would change the database at run-time with the SetConnection method: (Note, the application used the ReportDocument object model.)

ReportDocument previewReport = new ReportDocument();
string reportPath = this.ReportField.SelectedValue;
DataSourceConnections dataSourceConnections = previewReport.DataSourceConnections; 
IConnectionInfo connectInfo = dataSourceConnections[0];
connectInfo.SetConnection(OracleServer, OracleDatabase, "username", "password");
CrystalReportViewer1.ReportSource = previewReport;

The new application uses the ReportClientDocument object model and retrieves the report from the Crystal Server. The application can successfully provide logon information to the report for the database configuration the report was saved with:

 //logon to enterprise and get & open report
 SessionMgr sessionMgr = new SessionMgr();
 EnterpriseSession enterpriseSession = sessionMgr.Logon(userName, password, serverName, "secEnterprise");
 EnterpriseService enterpriseService = enterpriseSession.GetService("InfoStore");
 InfoStore infoStore = new InfoStore(enterpriseService);
 enterpriseService = enterpriseSession.GetService("RASReportFactory");
 ReportAppFactory reportAppFactory = (ReportAppFactory)enterpriseService.Interface;
 string queryString = "Select SI_ID, SI_NAME, SI_PARENTID From CI_INFOOBJECTS "
                    + "Where SI_PROGID='CrystalEnterprise.Report' "
                    + "And SI_NAME='" + reportType + "'"
                    + "And SI_PARENT_FOLDER='" + folderValue + "'";
 InfoObjects infoObjects = infoStore.Query(queryString);
 reportClientDocument = new ReportClientDocument();

 if (infoObjects.Count > 0)
    InfoObject infoObject = infoObjects[1];
    reportClientDocument = reportAppFactory.OpenDocument(infoObject.ID, 0);
    DatabaseController databaseController = reportClientDocument.DatabaseController;
    databaseController.logon(databaseUserName, databasePassword);
    crystalReportViewer.ReportSource = reportClientDocument;

The problem occurs when we have the new application try to change the database at runtime. We're having the application use the ReplaceConnection method (See code below). Instead of displaying the report as expected, we are prompted with "Enter Values", "The report you requested requires further information." along with fields for "Server name:" which is blank and disabled, "Database name:" which is blank and disabled, "User name:" which is filled in with the correct username, "Password:" which is blank, and a "Use Integrated Security" checkbox which is unchecked.

DatabaseController databaseController = reportClientDocument.DatabaseController;
ConnectionInfos connectionInfos = databaseController.GetConnectionInfos(null);

CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo oldConnectionInfo = connectionInfos[0];
CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo newConnectionInfo = 
                               new CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo();
newConnectionInfo.Kind = CrConnectionInfoKindEnum.crConnectionInfoKindCRQE;
PropertyBag QELogonProperties = new PropertyBag();
QELogonProperties.Add("Server", OracleDevelopmentDatabaseServer);
QELogonProperties.Add("Trusted Connection", false);
PropertyBag QEProperties = new PropertyBag();
QEProperties.Add("QE_LogonProperties", QEProperties);
QEProperties.Add("Database DLL", "crdb_oracle.dll");
QEProperties.Add("QE_DatabaseName", "");
QEProperties.Add("QE_DatabaseType", "Oracle Server");
QEProperties.Add("QE_ServerDescription", OracleDevelopmentDatabaseServer);
QEProperties.Add("QE_SQLDB", true);
QEProperties.Add("SSO Enabled", false);

newConnectionInfo.Attributes = QEProperties;
newConnectionInfo.UserName = "username";
newConnectionInfo.Password = "password";
databaseController.ReplaceConnection(oldConnectionInfo, newConnectionInfo, null,
crystalReportViewer.ReportSource = reportClientDocument;

What we're trying to figure out is what is the ReportClientDocument equivalent of SetConnection? Isn't it ReplaceConnection?

We're using VS2010 with BI 4.0 SP2 Enterprise .NET SDK (the 14.0.2000.0 dlls).