Auto Reconnect
The CLI-based Connectivity Kits now have the ability to automatically reconnect after a lost connection.
A lost connection situation occurs if, for some reason, the connection between a workstation and the database server has been lost. This can be caused by several reasons:
- Network hiccups, which are more likely on WAN connections and Wi-Fi networks.
- Connections may be lost after a certain period of inactivity.
- The database server can be temporarily unavailable due to maintenance or backups.
Earlier versions of the Connectivity Kit did not handle lost connection situations. After the connection from a DataFlex program to a database server was lost, the Connectivity Kit was unable to re-establish the connection. This meant that after an interrupted connection, even if it was only for a short while, all database operations from the program would generate ‘connection lost’ errors. The only solution was to end the DataFlex program and restart it.
Reconnect Logic
The Connectivity Kits version 6 will now try to reconnect to the database server when a connection lost error has been received:
- If the reconnect succeeds (the connection is re-established), the operation that generated the lost connection error (for example, a Find operation) will be retried.
- If the reconnect does not succeed (unable to connect to the database server), a ‘connection lost’ error will be generated.
Notes
After a successful reconnection inside a Find operation, it will appear to the program as if nothing has happened. The program has executed a successful Find operation and is unaware that a reconnect has taken place. Note that this will only occur if the first reconnect attempt is successful.
If the first reconnect attempt fails, the Find operation will generate a ‘connection lost’ error. The next Find operation from the program will again try to reconnect.
After receiving a connection lost error, the Connectivity Kit will not try to reconnect when it is inside a transaction. Instead, it will generate a ‘lost connection’ error, which will abort and roll back the transaction. The first operation after the transaction will try to reconnect, and if successful, the program can continue.
Re-executing the operation after a successful reconnect will only be done on Find and Open operations. Save and Delete operations always take place inside a transaction and will not try to reconnect, but will generate an error that will cause a transaction abort.
Configure AutoReconnect
Auto-Reconnect can be configured in the Connectivity Kit configuration file (mssqldrv.int, db2_drv.int, or odbc_drv.int) with the following keyword:
AUTO_RECONNECT 1
The default value is 1 (Auto-reconnect on).
Connection Lost Error
The Connectivity Kit will generate the following error when the connection to the database is lost:
12343 DFODBCERR_DATABASECONNECTIONLOST
Connection to database lost
The Connectivity Kit will translate the database native connection lost errors to this DataFlex error code.
For the SQL Server and DB2 Connectivity Kits, the native connection lost errors are pre-configured and do not have to be set up.
The ODBC Connectivity Kit can connect to different database backends, and the connection lost state(s) must be specified in the database-specific configuration file like Oracle.int, Mysql.int, Access.int, etc.
The connection lost state can be specified with the CONNECTION_LOST_STATE keyword. If there are multiple connection lost states, the CONNECTION_LOST_STATE keyword can be specified multiple times.
Example (MySQL.INT)
; Connection_Lost_State
; The native error that indicates a lost connection.
; This error will translate to a DF lost connection error.
Connection_Lost_State 08S01
See Also
- Connectivity Kits Version 6