Skip to content

RedirectConnectionId - cConnection

Redirects a connection from one Server String to another without closing any tables

Type: Function
Return Data Type: Boolean

Parameters

Parameter Type Description
sId String Connection ID
sServer String Server String
sUID String User ID
sPWD String Password
bTrusted Boolean Use Trusted Connection?
bKeepOpen Boolean Keep Logged In?

Syntax

Function RedirectConnectionId String sId String sServer String sUID String sPWD Boolean bTrusted Boolean bKeepOpen Returns Boolean

Call Example

Get RedirectConnectionId sId sServer sUID sPWD bTrusted bKeepOpen to BooleanVariable

Description

Redirects a connection from one Server String to another without closing any tables.

In addition, this method will keep existing connections alive so they can be switched back to without requiring a login. If the server is already logged into, switching back to that server will be very fast.

The RedirectConnectionId function is passed a Connection ID, a server string and login credentials. If a login is needed, those credentials must succeed. It is also passed a keep-alive flag, which, if True, will keep the connection being directed from connected.

RedirectConnectionId does not refresh any table or DD buffers, developers will need to handle this themselves.

Sample

In this example, the RedirectTest method will direct the connection to the passed server string. In this case, we assume trusted connections are used with all connections.

Procedure RedirectTest String sID1 String sServer
    Boolean bOk
    Get RedirectConnectionId of ghoConnection sID1 sServer "" "" True True to bOk
    If Not bOk Begin
        // handle error
    End
End_Procedure
:
Send RedirectTest "Id1" ".\SQLEXPRESS;DATABASE=Order_1"
:
Send RedirectTest "Id1" ".\SQLEXPRESS;DATABASE=Order_2"

Sample

This sample handles a connection redirect by changing the default database for a connection (this only supports databases on the same server instance)

Object oConnection is a cConnection
    Use LoginEncryption.pkg

    //
    //  Switch between databases by changing the detault database for the connection.
    //  This only works if the database is on the same server.
    //
    Procedure SwitchTenantDb String sDatabaseName
        tConnection coninfo
        Handle  hConnectionHandle hConnectionHandle2       
        String sValue sDefaultDatabase     
        Integer iDriverIndex  

        Get ConnectionIdInfo "TenantData" to coninfo

        If (coninfo.iDriverIndex) Begin
            Get ConnectionDatabaseIdHandle of ghoConnection coninfo to hConnectionHandle

            If (hConnectionHandle) Begin
                Get_Attribute DF_DATABASE_DEFAULT_DATABASE of coninfo.iDriverIndex hConnectionHandle to sDefaultDatabase
                If (sDefaultDatabase <> sDatabaseName) Begin
                    Set_Attribute DF_DATABASE_DEFAULT_DATABASE of coninfo.iDriverIndex hConnectionHandle to sDatabaseName
                End
            End
        End
    End_Procedure

End_Object

If bKeepLoggedIn = False, the new connection will be logged in, the old connection will be logged out. If bKeepLoggedIn = True, connections will remain open and re-used on next redirectIdConnection.

This is an advanced and powerful capability and must be used with caution. Note that: An existing connection must exist (must be logged in to) before RedirectConnectionId can be called. The password credentials for the new connection must succeed for the new login. It is your responsibility to make sure that any application data being displayed is properly cleared or initialized after the connection redirect.

Return Value

Status: True = Success, False = Failed