Skip to content

RedirectConnection - cCLIHandler

(Obsolete) Redirects an existing connection. Returns whether redirection was successful.

Type: Function
Return Data Type: Integer

Parameters

Parameter Type Description
sOldConnection String The original connection that is being redirected from
sNewConnection String The new connection that is being redirected to

Syntax

Function RedirectConnection String sOldConnection String sNewConnection Returns Integer

Call Example

Get RedirectConnection sOldConnection sNewConnection to IntegerVariable

Description

(Obsolete)

As of DataFlex 19.0, Connection Ids are handled via Managed Connections, making this method obsolete. All of these techniques still work, but they have been replaced with better techniques that are also managed via the Studio and other DataFlex tools. See the cConnection class, RedirectConnectionId and Managed Connections for more.

This function allows to redirect an existing connection. When used, the connection will change (point to another database) but the tables stay open. This is intended to be used in cases where a program must switch between databases that are identical in definition.

The function gets two string parameters, sOldConnection and sNewConnection. It will check if the original connection exists, login to the new connection, redirect the open tables and logout from the old connection.

The parameters should contain the string that identifies the database connection. This is usually what can be found in the DF_FILE_LOGIN attribute of a table.

If, for example, we want to redirect the connection to an SQL Server database from database DBX to database DBY both on database server S we would use:

Get RedirectConnection "SERVER=S;Trusted_Connection=yes;DATABASE=DBX" ;
                       "SERVER=S;Trusted_Connection=yes;DATABASE=DBY" ;
                       To iResult

A connection can only be redirected if all tables that are open in the original connection are also present with an identical definition in the new connection.

See Also

DataFlex Connection IDs

Return Value

Returns 0 when the redirection was successful. A return value of 1 means the original connection does not exist. A return value of 2 means logging into the new connection failed.