|
Report Application Server .NET SDK Developer Guide
|
|
To change a persistent data source
|
|
See Also
|
Persistent data sources provide data for a report that exists both within and beyond runtime scope. The recommended way to change your persistent data source is to use the CrystalDecisions.ReportAppServer.Controllers.DatabaseController.ReplaceConnection method.
Each table used by a report requires a properly configured data source connection, represented by a ConnectionInfo object. The ReplaceConnection method automatically propagates your new data source connection to all tables in the report that use the old connection.
|
Note
|
|
If instead you want to change the connection for a particular table, you can do so using one of the SetTableLocation methods available in the DatabaseController class.
|
The following steps show how to change a single data source connection for all tables in a report to a new ODBC connection. However, the fundamental workflow described can be applied to any type of data source.
- Retrieve the DatabaseController object.
|
Visual Basic
|
|
|
Dim databaseController As DatabaseController = rcd.DatabaseController
|
|
C#
|
|
|
DatabaseController databaseController = rcd.DatabaseController;
|
- Retrieve the collection of all data source connections in the report.
|
Visual Basic
|
|
|
Dim connectionInfos As ConnectionInfos = databaseController.GetConnectionInfos(Nothing)
|
|
C#
|
|
|
ConnectionInfos connectionInfos = databaseController.GetConnectionInfos(null);
|
- Use the Item property of the ConnectionInfos collection to retrieve a single connection.
|
Note
|
|
This example assumes the report has a single data source. Different tables in your report may have different data source connections, and you can change the connection for each in the collection as necessary.
|
|
Visual Basic
|
|
|
Dim oldConnectionInfo As ConnectionInfo = connectionInfos.Item(0)
|
|
C#
|
|
|
ConnectionInfo oldConnectionInfo = connectionInfos[0];
|
- Create a new ConnectionInfo object to represent the new data source connection.
|
Visual Basic
|
|
|
Dim newConnectionInfo As ConnectionInfo = New ConnectionInfoClass() newConnectionInfo.Kind = CrConnectionInfoKindEnum.crConnectionInfoKindCRQE
|
|
C#
|
|
|
ConnectionInfo newConnectionInfo = new ConnectionInfoClass(); newConnectionInfo.Kind = CrConnectionInfoKindEnum.crConnectionInfoKindCRQE;
|
- Create a new PropertyBag object and add the custom logon properties specific to the new data source type.
|
Visual Basic
|
|
|
Dim QELogonProperties As PropertyBag = New PropertyBag() QELogonProperties.Add("DSN", "Your Database") QELogonProperties.Add("UseDSNProperties", False)
|
|
C#
|
|
|
PropertyBag QELogonProperties = new PropertyBag(); QELogonProperties.Add("DSN", "Your Database"); QELogonProperties.Add("UseDSNProperties", false);
|
- Create a new PropertyBag object and add the custom logon properties, as well as the default connection properties for the new data source.
|
Visual Basic
|
|
|
Dim QEProperties As PropertyBag = New PropertyBag() QEProperties.Add("QE_LogonProperties", QELogonProperties) QEProperties.Add("Database DLL", "crdb_odbc.dll") QEProperties.Add("QE_DatabaseName", "") QEProperties.Add("QE_DatabaseType", "ODBC (RDO)") QEProperties.Add("QE_ServerDescription", "Your Database") QEProperties.Add("QE_SQLDB", True) QEProperties.Add("SSO Enabled", False)
|
|
C#
|
|
|
PropertyBag QEProperties = new PropertyBag(); QEProperties.Add("QE_LogonProperties", QELogonProperties); QEProperties.Add("Database DLL", "crdb_odbc.dll"); QEProperties.Add("QE_DatabaseName", ""); QEProperties.Add("QE_DatabaseType", "ODBC (RDO)"); QEProperties.Add("QE_ServerDescription", "Your Database"); QEProperties.Add("QE_SQLDB", true); QEProperties.Add("SSO Enabled", false);
|
- Use the Attributes property of the ConnectionInfo object to set the connection properties of the new data source.
|
Visual Basic
|
|
|
newConnectionInfo.Attributes = QEProperties
|
|
C#
|
|
|
newConnectionInfo.Attributes = QEProperties;
|
- Set the user name and password credentials for the new data source.
|
Visual Basic
|
|
|
newConnectionInfo.setUserName("username") newConnectionInfo.setPassword("password")
|
|
C#
|
|
|
newConnectionInfo.UserName = "" newConnectionInfo.Password = null
|
- Call the ReplaceConnection method of the DatabaseController object to change your old data source connection to the new connection.
|
Visual Basic
|
|
|
databaseController.ReplaceConnection(oldConnectionInfo, newConnectionInfo, Nothing, CrDBOptionsEnum.crDBOptionUseDefault + CrDBOptionsEnum.crDBOptionDoNotVerifyDB)
|
|
C#
|
|
|
databaseController.ReplaceConnection(oldConnectionInfo, newConnectionInfo, null, (int)CrDBOptionsEnum.crDBOptionUseDefault + (int)CrDBOptionsEnum.crDBOptionDoNotVerifyDB);
|
The following code changes all the tables in a single data source connection to a new OBDC connection.
|
Note
|
|
The CrDBOptionsEnum.crDBOptionDoNotVerifyDB enumeration forces the connection data to be verified immediatly rather then verified at run time.
|
|
Visual Basic
|
|
|
Private Sub ChangeDataSource(ByVal rcd As ISCDReportClientDocument) Dim databaseController As DatabaseController = rcd.DatabaseController Dim connectionInfos As ConnectionInfos = databaseController.GetConnectionInfos(Nothing) Dim oldConnectionInfo As ConnectionInfo = connectionInfos.Item(0) Dim newConnectionInfo As ConnectionInfo = New ConnectionInfoClass() newConnectionInfo.Kind = CrConnectionInfoKindEnum.crConnectionInfoKindCRQE Dim QELogonProperties As PropertyBag = New PropertyBag() QELogonProperties.Add("DSN", "Your Database") QELogonProperties.Add("UseDSNProperties", False) Dim QEProperties As PropertyBag = New PropertyBag() QEProperties.Add("QE_LogonProperties", QELogonProperties) QEProperties.Add("Database DLL", "crdb_odbc.dll") QEProperties.Add("QE_DatabaseName", "") QEProperties.Add("QE_DatabaseType", "ODBC (RDO)") QEProperties.Add("QE_ServerDescription", "Your Database") QEProperties.Add("QE_SQLDB", True) QEProperties.Add("SSO Enabled", False) newConnectionInfo.Attributes = QEProperties newConnectionInfo.setUserName("username") newConnectionInfo.setPassword("password") databaseController.ReplaceConnection(oldConnectionInfo, newConnectionInfo, Nothing, CrDBOptionsEnum.crDBOptionUseDefault + CrDBOptionsEnum.crDBOptionDoNotVerifyDB) End Sub
|
|
C#
|
|
|
private void ChangeDataSource(ISCDReportClientDocument rcd) { DatabaseController databaseController = rcd.DatabaseController; ConnectionInfos connectionInfos = databaseController.GetConnectionInfos(null); ConnectionInfo oldConnectionInfo = connectionInfos[0]; ConnectionInfo newConnectionInfo = new ConnectionInfoClass(); newConnectionInfo.Kind = CrConnectionInfoKindEnum.crConnectionInfoKindCRQE; PropertyBag QELogonProperties = new PropertyBag(); QELogonProperties.Add("DSN", "Your Database"); QELogonProperties.Add("UseDSNProperties", false); PropertyBag QEProperties = new PropertyBag(); QEProperties.Add("QE_LogonProperties", QELogonProperties); QEProperties.Add("Database DLL", "crdb_odbc.dll"); QEProperties.Add("QE_DatabaseName", ""); QEProperties.Add("QE_DatabaseType", "ODBC (RDO)"); QEProperties.Add("QE_ServerDescription", "Your Database"); QEProperties.Add("QE_SQLDB", true); QEProperties.Add("SSO Enabled", false); newConnectionInfo.Attributes = QEProperties; newConnectionInfo.UserName = "username"; newConnectionInfo.Password = "password"; databaseController.ReplaceConnection(oldConnectionInfo, newConnectionInfo, null, (int)CrDBOptionsEnum.crDBOptionUseDefault + (int)CrDBOptionsEnum.crDBOptionDoNotVerifyDB); }
|
This list includes the namespaces used by the sample code:
- CrystalDecisions.Enterprise
- CrystalDecisions.ReportAppServer.ClientDoc
- CrystalDecisions.ReportAppServer.Controllers
- CrystalDecisions.ReportAppServer.DataDefModel
See Also
© 2021 SAP AG. All rights reserved.
http://www.sap.com/sapbusinessobjects/
Support services
http://service.sap.com/bosap-support/
Created with the Personal Edition of HelpNDoc: Easy to use tool to create HTML Help files and Help web sites