1535347 - How to replace database connection information used by a Crystal Reports in a VS .NET project?

SAP Knowledge Base Article - Public

1535347 - How to replace database connection information used by a Crystal Reports in a VS .NET project?

Symptom

  • SQL Database Vendor Code of 2812 (other Database Vendor Code errors possible - depending on the database and connection type)
  • After calling method ApplyLogOnInfo, the logon information in each table of ReportDocument does not change
  • Database login prompts when changing database connection type (e.g.; crdb_dao.dll to crdb_adoplus.dll)
  • Slow running reports

Resolution

private void ReplaceConnection_Click(object sender, EventArgs e)
{
CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
ISCDReportClientDocument rcd;
rcd = rptClientDoc;
rptClientDoc.DatabaseController.LogonEx("dwcb12003", "xtreme", "sb", "pw");
//Create the logon propertybag for the connection we wish to use
CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag logonDetails = new CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag();
logonDetails.Add("Auto Translate", -1);
logonDetails.Add("Connect Timeout", 15);
logonDetails.Add("Data Source", "dwcb12003");
logonDetails.Add("General Timeout", 0);
logonDetails.Add("Initial Catalog", "Orders");
logonDetails.Add("Integrated Security", "True");
logonDetails.Add("Locale Identifier", 1033);
logonDetails.Add("OLE DB Services", -5);
logonDetails.Add("Provider", "SQLOLEDB");
logonDetails.Add("Use Encryption for Data", 0);
logonDetails.Add("Owner", "dbo"); // schema
//Create the QE (query engine) propertybag with the provider details and logon property bag.
CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag QE_Details = new CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag();
QE_Details.Add("Database DLL", "crdb_ado.dll");
QE_Details.Add("QE_DatabaseName", "Orders");
QE_Details.Add("QE_DatabaseType", "OLE DB (ADO)");
QE_Details.Add("QE_LogonProperties", logonDetails);
QE_Details.Add("QE_ServerDescription", "dwcb12003");
QE_Details.Add("QE_SQLDB", "True");
QE_Details.Add("SSO Enabled", "False");
QE_Details.Add("Owner", "dbo");
CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo newConnInfo = new CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo();
CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo oldConnInfo;
CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfos oldConnInfos;
oldConnInfos = rcd.DatabaseController.GetConnectionInfos(null);
for (int I = 0; I < oldConnInfos.Count; I++)
{
oldConnInfo = oldConnInfos;
newConnInfo.Attributes = QE_Details;
newConnInfo.Kind = CrystalDecisions.ReportAppServer.DataDefModel.CrConnectionInfoKindEnum.crConnectionInfoKindCRQE;
rcd.DatabaseController.ReplaceConnection(oldConnInfo, newConnInfo, null, CrystalDecisions.ReportAppServer.DataDefModel.CrDBOptionsEnum.crDBOptionDoNotVerifyDB);
}
}

See Also

Keywords

KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , How To

Product

Crystal Reports 2008 V1

Attachments

CodeBuilder-RasConnectionInfo (cr 2008 net2008).zip