In this video, you learn about a feature which allows ABL clients to automatically connect to an alternate database, if the connection to the primary database fails. This mechanism helps ensure the continuous operation of the client application.

Demo code

The following code is used in the demo:

my.pf:

-db sports2020 -H localhost -S 5550 -ct 1
-dbalt1 "sports2020 -H localhost -S 5551"
-retryConnect 1 
-retryConnectPause 2

dbconnet.p:

/* ***************************  Definitions  ************************** */

BLOCK-LEVEL ON ERROR UNDO, THROW.

/* ********************  Preprocessor Definitions  ******************** */


/* ***************************  Main Block  *************************** */
REPEAT:

IF NOT CONNECTED("sports2020") THEN
CONNECT "-pf my.pf".

RUN getcustomers.p.

CATCH e1 AS PROGRESS.lang.stopError:
    MESSAGE "Caught stoperror " e1:getmessage(1)
            "about to run dbconnect.p so we can re-connect"
            VIEW-AS ALERT-BOX.
    IF CONNECTED("sports2020") THEN 
    RETURN.            
END.

END.

getcustomers.p:

/* ***************************  Definitions  ************************** */

BLOCK-LEVEL ON ERROR UNDO, THROW.

/* ********************  Preprocessor Definitions  ******************** */


/* ***************************  Main Block  *************************** */
FOR EACH customer.
DISPLAY custnum name.
PAUSE 1.
END.

autoreconnect.pf:

-db sports2020 -H localhost -S 5550 -ct 1
-dbalt1 "sports2020 -H localhost -S 5551"
-retryConnect 1 
-retryConnectPause 2
-autoReconnect
Note: The only difference between autoreconnect.pf and my.pf is the inclusion of the -autoreconnect startup parameter. This parameter enables your procedure to attempt reconnection to all databases listed in the parameter file if a disconnection occurs. Without -autoreconnect, the procedure would simply terminate. You would use this parameter file instead of my.pf.