Hi,
I'm trying to change database for a report in runtime.
We had a working solution for this. But when upgrading from CR 12.3.2000 (CR 2008) it stopped working.
The problem I can see is that when changing the values for ServerName, UserID and Password on the ConnectionInfo object and then try to set the new values to each table in the report by calling ApplyLogOnInfo the values from the report file are reinstated.
I have reade dosens of threads and discussions on similar problems and I have tried to make the changes by using several different methods described in this forum and in other. I have used the code generating utility (KB - 1553921).
I also downloaded sampels from this site that is suppose to be able to connect to another Oracle database. The sample is called (csharp_win_oraclelogoninfo).
Non of the code or the sample application i have tried works.
Independent of what way I try i get a COM exception like this:
To translate from Swedish, the error message is saying: It's not possible to load the database information. Error in file PickList_EL.........rpt
Here is the original code used:
private void SetReportConnectionInfo(ConnectionInfo connectionInfo, ReportDocument reportDocument)
{
foreach (Table table in reportDocument.Database.Tables)
{
table.LogOnInfo.ConnectionInfo.ServerName = connectionInfo.ServerName;
table.LogOnInfo.ConnectionInfo.UserID = connectionInfo.UserID;
table.LogOnInfo.ConnectionInfo.Password = connectionInfo.Password;
table.ApplyLogOnInfo(table.LogOnInfo);
}
}
The ConnectionInfo passed to the function is just a new instance of ConnectionInfo containing the new ServerName, UserId and Password
I have tried different versions of this method where I create new objects for LogOnInfo and ConnectionInfo and allso setting the Attributes collection and so on. Nothing of this works.
I also implemented the code generated by the utility tool like this:
private void SetReportConnectionInfo(string DB_Name, string DB_user, string DB_password, ReportDocument reportDocument)
{
//Create a new Database Table to replace the reports current table.
CrystalDecisions.ReportAppServer.DataDefModel.Table newTable = new CrystalDecisions.ReportAppServer.DataDefModel.Table();
//newMainPropertyBag: These hold the attributes of the tables ConnectionInfo object
PropertyBag newMainPropertyBag = new PropertyBag();
//newInnerPropertyBag: These hold the attributes for the QE_LogonProperties
//In the main property bag (newMainPropertyBag)
PropertyBag newInnerPropertyBag = new PropertyBag();
//Set the attributes for the newInnerPropertyBag
newInnerPropertyBag.Add("Server", DB_Name);
newInnerPropertyBag.Add("Trusted_Connection", "False");
//Set the attributes for the newMainPropertyBag
newMainPropertyBag.Add("Database DLL", "crdb_oracle.dll");
newMainPropertyBag.Add("QE_DatabaseName", "");
newMainPropertyBag.Add("QE_DatabaseType", "");
//Add the QE_LogonProperties we set in the newInnerPropertyBag Object
newMainPropertyBag.Add("QE_LogonProperties", newInnerPropertyBag);
newMainPropertyBag.Add("QE_ServerDescription", DB_Name);
newMainPropertyBag.Add("QE_SQLDB", "False");
newMainPropertyBag.Add("SSO Enabled", "False");
//Create a new ConnectionInfo object
CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo newConnectionInfo = new CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo();
//Pass the database properties to the connection info object
newConnectionInfo.Attributes = newMainPropertyBag;
//Set the connection kind
newConnectionInfo.Kind = CrConnectionInfoKindEnum.crConnectionInfoKindCRQE;
//Set the User Name and Password if required.
newConnectionInfo.UserName = DB_user;
newConnectionInfo.Password = DB_password;
//Pass the connection information to the table
newTable.ConnectionInfo = newConnectionInfo;
//Get the Database Tables Collection for your report
CrystalDecisions.ReportAppServer.DataDefModel.Tables existingTables;
existingTables = reportDocument.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
foreach (CrystalDecisions.ReportAppServer.DataDefModel.Table table in existingTables)
{
newTable.Name = table.Name; // "PBHEAD";
newTable.QualifiedName = table.QualifiedName; // "OWUSER.PBHEAD";
newTable.Alias = table.Alias; // "PBHEAD";
reportDocument.ReportClientDocument.DatabaseController.SetTableLocation(table, newTable);
}
//Verify the database after adding substituting the new table.
//To ensure that the table updates properly when adding Command tables or Stored Procedures.
reportDocument.VerifyDatabase();
}
This fails at "reportDocument.ReportClientDocument.DatabaseController.SetTableLocation(table, newTable);"
Now I'm all out of ideas at the moment. But I hope someone else is not.
Best regards
Anders Rongby