I'm writing a 'general purpose' back-end, that needs to provide basic operations, to load a Crystal Reports report.
Using the connection string I get from the client app (a test program, at the moment), I build a ConnectionInfo object and apply it to the table(s) of the selected report (+ sub reports):
CRS.TableLogOnInfo tableLogOnInfo = table.LogOnInfo;
tableLogOnInfo.ConnectionInfo.ServerName = connectionInfo.ServerName;
tableLogOnInfo.ConnectionInfo.DatabaseName = connectionInfo.DatabaseName;
tableLogOnInfo.ConnectionInfo.UserID = connectionInfo.UserID;
tableLogOnInfo.ConnectionInfo.Password = connectionInfo.Password;
If I halt the debugger on the last line, table contains the correct information. Once I execute the ApplyLogOnInfo, it seems to have restored the original connection, provided in the report itself.
The reports used are delivered to me, I have zero control regarding the content, so I have to make them work as is.
Any idea why ApplyLogOnInfo doesn't accept my changes?
PS: I am using Visual Studio 2010, so with Crystal Reports 2011
I am assuming that you are trying to point the report to a different database i.e. changing the database of a report at runtime.
I am not sure if ApplyLogonInfo will allow you to change the database, as it only provides the logon information to the report at runtime.
You will have to make use of the RAS SDK Property bags to change the database at runtime.
Take a look at the [RAS .NET SDK Developer Guide|http://help.sap.com/businessobject/product_guides/sapCRVS2010/en/xi4_rassdk_net_dg_en.zip]
Also take a look at the code which gets generated by the util[1553921 - Is there a utility that would help in writing database logon code? |http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_bi/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes%7B6163636573733d36393736354636443646363436353344333933393338323636393736354637333631373036453646373436353733354636453735364436323635373233443330333033303331333533353333333933323331%7D.do] in writing database logon code?
Hope it helps,
Using the provided code (and other sources) I came up with the method found below. Main difference is that I am trying to connect to Sql Server, where the sample connects to MS Access.
Maybe I am missing something in those properties, because I am unable to login. It just fails, even though I know the credentials are correct. Prior to my CR calls, I do a CanConnect check of the provided connection string, so if I am in the CR code, I know the credentials are valid...
private CR.ReportDocument SetLogon(CR.ReportDocument report, CRS.ConnectionInfo connectionInfo)
//Create a new Command Table to replace the reports current table.
CrystalDecisions.ReportAppServer.DataDefModel.CommandTable newTable =
RASD.PropertyBag logonDetails = new RASD.PropertyBag();
logonDetails.Add("Auto Translate", -1);
logonDetails.Add("Connect Timeout", 15);
logonDetails.Add("Data Source", connectionInfo.ServerName);
logonDetails.Add("General Timeout", 0);
logonDetails.Add("Initial Catalog", connectionInfo.DatabaseName);
logonDetails.Add("Integrated Security", "False");
logonDetails.Add("Locale Identifier", 5129);
logonDetails.Add("OLE DB Services", -5);
logonDetails.Add("Tag with column collation when possible", 0);
logonDetails.Add("Use DSN Default Properties", "False");
logonDetails.Add("Use Encryption for Data", 0);
//logonDetails.Add("Owner", "dbo"); // schema
//Add the QE_LogonProperties we set in the boInnerPropertyBag Object
RASD.PropertyBag mainProperties = new RASD.PropertyBag();
mainProperties.Add("Database DLL", "crdb_ado.dll");
mainProperties.Add("QE_DatabaseType", "OLE DB (ADO)");
mainProperties.Add("SSO Enabled", "False");
//Create a new ConnectionInfo object
CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo newConnectionInfo =
//Pass the database properties to a connection info object
newConnectionInfo.Attributes = mainProperties;
//Set the connection kind
newConnectionInfo.Kind = RASD.CrConnectionInfoKindEnum.crConnectionInfoKindCRQE;
//Set the User Name and Password.
newConnectionInfo.UserName = connectionInfo.UserID;
newConnectionInfo.Password = connectionInfo.Password;
//Pass the connection information to the table
newTable.ConnectionInfo = newConnectionInfo;
//Get the Database Tables Collection for your report
reportTables = report.ReportClientDocument.DatabaseController.Database.Tables;
foreach (RASD.Table reportTable in reportTables)
newTable.Name = reportTable.Name;
newTable.QualifiedName = connectionInfo.DatabaseName + "." + reportTable.Name;
newTable.Alias = reportTable.Alias;
//Verify the database after adding substituting the new table.
//To ensure that the table updates properly when adding Command tables or Stored Procedures.
Additionally, I have a form that lists the available reports. When calling a second report, setting report parameter values does not seem to have effect either. The code is run every single time, but still the report preview screen asks for input, as if it has never been provided. On the first load, it works just fine.
All of my code is 'inspired' by an existing (old) application, that runs on Crystal Reports 11. Prior to my current attempts, I did not have CR installed, but am now running the 2011 version.
Mine and the original code does not work, when I run it locally. Which is strange, considering the original app is long-proven technology.
So, one conclusion is that the new CR 2011 version seems to conflict, as if old functionality works, but is now in effect obsolete.
Also, I wonder if CR is very sensitive to errors. I mean then 'forgetting' to set certain options/values, or doing things in an unexpected order.