Comment faire pour modifier les rapports Crystal propriétés de connexion dans le code?

Arrière lorsque Crystal Reports prend toujours en charge ActiveX, nous avons crystal reports qui ont été construits à l'utilisation de sources de données ODBC point d'Accès ou de base de données SQL. Au moment de l'exécution, nous permettrait de changer le rapport à l'utilisation de OLE DB (ADO) au lieu de ODBC, modifier le nom du serveur, nom de base de données, nom d'utilisateur, mot de passe à celles spécifiques à l'utilisateur, et d'exécuter le rapport, il a bien fonctionné.

Maintenant que Crystal Reports 2008 ne prend plus en charge ActiveX, nous essayons de faire la même chose .NET, mais sans succès.

Voici le code pour l'instant:

Public Function ChangeConnectionInfo() As ReportDocument
Dim boReportDocument As New ReportDocument
'**EDIT** Change the path and report name to the report you want to change.
boReportDocument.Load("c:\CustomerListSQL.Rpt", OpenReportMethod.OpenReportByTempCopy)
'Create a new Command Table to replace the reports current table.
Dim boTable As New CrystalDecisions.ReportAppServer.DataDefModel.CommandTable
'boMainPropertyBag: These hold the attributes of the tables ConnectionInfo object
Dim boMainPropertyBag As New PropertyBag
'boInnerPropertyBag: These hold the attributes for the QE_LogonProperties
'In the main property bag (boMainPropertyBag)
Dim boInnerPropertyBag As New PropertyBag
'Set the attributes for the boInnerPropertyBag
boInnerPropertyBag.Add("Auto Translate", "-1")
boInnerPropertyBag.Add("Connect Timeout", "15")
boInnerPropertyBag.Add("Data Source", "K2")
boInnerPropertyBag.Add("General Timeout", "0")
boInnerPropertyBag.Add("Initial Catalog", "DBNAME")
boInnerPropertyBag.Add("Integrated Security", "True")
boInnerPropertyBag.Add("Locale Identifier", "5129")
boInnerPropertyBag.Add("OLE DB Services", "-5")
boInnerPropertyBag.Add("Provider", "SQLOLEDB")
boInnerPropertyBag.Add("Tag with column collation when possible", "0")
boInnerPropertyBag.Add("Use DSN Default Properties", "False")
boInnerPropertyBag.Add("Use Encryption for Data", "0")
'Set the attributes for the boMainPropertyBag
boMainPropertyBag.Add("Database DLL", "crdb_ado.dll")
boMainPropertyBag.Add("QE_DatabaseName", "DBNAME")
boMainPropertyBag.Add("QE_DatabaseType", "OLE DB (ADO)")
'Add the QE_LogonProperties we set in the boInnerPropertyBag Object
boMainPropertyBag.Add("QE_LogonProperties", boInnerPropertyBag)
boMainPropertyBag.Add("QE_ServerDescription", "K2")
boMainPropertyBag.Add("QE_SQLDB", "True")
boMainPropertyBag.Add("SSO Enabled", "False")
'Create a new ConnectionInfo object
Dim boConnectionInfo As 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
Dim boTables As CrystalDecisions.ReportAppServer.DataDefModel.Tables = _
boReportDocument.ReportClientDocument.DatabaseController.Database.Tables    
'For each table in the report:
' - Set the Table Name properties.
' - Set the Command table's command text.
' - Set the table location in the report to use the new modified table
For Each boReportTable In boTables
boTable.Name = boReportTable.Name
boTable.QualifiedName = "DBNAME.dbo." + boReportTable.Name 'boReportTable.QualifiedName
boTable.Alias = boReportTable.Alias    
boReportDocument.ReportClientDocument.DatabaseController.SetTableLocation(boReportTable, boTable)
Next
'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()
Return boReportDocument
End Function

Le code fonctionne jusqu'à ce qu'il arrive à boReportDocument.VerifyDatabase(), c'est quand je reçois un 'connexion a Échoué' erreur.

J'ai essayé d'utiliser le code ici:

Le changement dynamique de la connexion d'un Rapport Crystal

Qui ne fonctionne pas non plus, je ne sais pas si cela a à voir avec commutation à partir d'ODBC, OLE DB (ADO)

InformationsquelleAutor Robo | 2010-02-01