DB2 Library

Temporary database connection errors are common when working with databases and can often be resolved by retrying after a delay.

The db2 library expands the built-in db table of functions by incorporating the retry functionality from the Retry Library | Iguana X Documentation into the standard database functions. The db2.connect() function sets up the database connection object with built-in retries whenever an error occurs. It takes the same arguments as the default db.connect() function, with two additional optional parameters:

  • retry_count - sets the number of retries to perform on the database connection (default = 100)

  • retry_pause - sets the time in seconds to wait between retries (default = 10)

For example, here we are initializing the database connection object with 10 retries and a pause of five seconds between each call:

local Conn = db2.connect{api=db.MY_SQL,name='MyDatabase',user='me',password='secret',retry_count=10,retry_pause=5}

Note: By default if the retries fail, an error will be thrown which will (usually) stop the channel.

You can import this library to add resiliency to your database interfaces. See how to Import a Library.