SAP Knowledge Base Article - Public

1702231 - How to change the XML WebService datasource of a Crystal report at runtime using InProc RAS .NET SDK?

Symptom

How to change the XML WebService datasource of a Crystal report at runtime using InProc RAS .NET SDK?

Environment

  • Crystal Reports 2008
  • Visual Studio 2008

Resolution

  • Here is the C# code snippet to change the Web Service datasource at runtime.
  • Specify the target datasource properties for boInnerPropertyBag and boMainPropertyBag.
  • Specify the Username and Password for connectioninfo.

 

//Add these required Crystal Assemblies to your project
CrystalDecisions.ReportAppServer.DataDefModel
CrystalDecisions.ReportAppServer.ClientDoc
CrystalDecisions.ReportAppServer.Controllers
CrystalDecisions.CrystalReports.Engine
CrystalDecisions.Shared
//Add these Crystal Assemblies to the top of your code page
using CrystalDecisions.ReportAppServer.DataDefModel;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
private ReportDocument ChangeConnectionInfo()
{
ReportDocument boReportDocument = new ReportDocument();
//**EDIT** Change the path and report name to the report you want to change.
boReportDocument.Load(@"c:\reports\yourreport.rpt", OpenReportMethod.OpenReportByTempCopy);
//Create a new Stored Procedure Table to replace the reports current table.
CrystalDecisions.ReportAppServer.DataDefModel.Procedure boTable =
new CrystalDecisions.ReportAppServer.DataDefModel.Procedure();
 
//boMainPropertyBag: These hold the attributes of the tables ConnectionInfo object
PropertyBag boMainPropertyBag = new PropertyBag();
//boInnerPropertyBag: These hold the attributes for the QE_LogonProperties
//In the main property bag (boMainPropertyBag)
PropertyBag boInnerPropertyBag = new PropertyBag();
 
//Set the attributes for the boInnerPropertyBag
boInnerPropertyBag.Add("Convert Mulitivalue to Table", "False");
boInnerPropertyBag.Add("Http(s) Schema URL", " ");
boInnerPropertyBag.Add("Http(s) XML URL", " ");
boInnerPropertyBag.Add("UserID Http(s) Schema", "");
boInnerPropertyBag.Add("UserID Http(s) XML", "");
 
//Set the attributes for the boMainPropertyBag
boMainPropertyBag.Add("Database DLL", "crdb_xml.dll");
boMainPropertyBag.Add("QE_DatabaseName", "");
boMainPropertyBag.Add("QE_DatabaseType", "XML and Web Services");
//Add the QE_LogonProperties we set in the boInnerPropertyBag Object
boMainPropertyBag.Add("QE_LogonProperties", boInnerPropertyBag);
boMainPropertyBag.Add("QE_ServerDescription", " ");
boMainPropertyBag.Add("QE_SQLDB", "False");
boMainPropertyBag.Add("SSO Enabled", "False");
//Create a new ConnectionInfo object
CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo boConnectionInfo =
new CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo();
//Pass the database properties to a connection info object
boConnectionInfo.Attributes = boMainPropertyBag;
//Set the connection kind
boConnectionInfo.Kind = CrConnectionInfoKindEnum.crConnectionInfoKindCRQE;
//**EDIT** Set the User Name and Password if required.
boConnectionInfo.UserName = "UserName";
boConnectionInfo.Password = "Password";
//Pass the connection information to the table
boTable.ConnectionInfo = boConnectionInfo;
//Get the Database Tables Collection for your report
CrystalDecisions.ReportAppServer.DataDefModel.Tables boTables;
boTables = boReportDocument.ReportClientDocument.DatabaseController.Database.Tables;
//For each table in the report:
// - Set the Table Name properties.
// - Set the table location in the report to use the new modified table
boTable.Name = " ";
boTable.QualifiedName = " ";
boTable.Alias = " ";
boReportDocument.ReportClientDocument.DatabaseController.SetTableLocation(boTables[0], boTable);
boTable.Name = " ";
boTable.QualifiedName = " ";
boTable.Alias = " ";
boReportDocument.ReportClientDocument.DatabaseController.SetTableLocation(boTables[1], boTable);
//Verify the database after adding substituting the new table.
//To ensure that the table updates properly when adding Command tables or Stored Procedures.
boReportDocument.VerifyDatabase();
//**EDIT** Set the value for the Stored Procedure parameters.
return boReportDocument;
}
 

Keywords

KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To

Product

Crystal Reports 2008 V1 ; SAP Crystal Reports 2011