Check connection status

If running in an environment where it is possible to have read-only connections, the status of the connection should be checked before doing committable updates. This will prevent the unit of work from entering the rollback required state.

The following COBOL example shows how to check the connection status.

Figure 1. Example of checking connection status
       …
        EXEC SQL
         SET CONNECTION SYS5
        END-EXEC.
        …
    * Check if the connection is updatable.
         EXEC SQL CONNECT END-EXEC.
    * If connection is updatable, update sales information otherwise
    * inform the user.
         IF SQLERRD(3) = 1 THEN
           EXEC SQL
             INSERT INTO SALES_TABLE
                 VALUES(:SALES-DATA)
            END-EXEC
          ELSE
            DISPLAY 'Unable to update sales information at this time'.
    …