ODBC and distributed units of work

You can write Db2 ODBC applications to use distributed units of work.

The transaction scenario that appears in How to connect to one or more data sources, portrays an application that can interact with only one data source in a transaction and perform only one transaction at a given time.

With a distributed unit of work (which is also called a coordinated distributed transaction), your application can access multiple database servers from within the same coordinated transaction.

The environment and connection attribute SQL_ATTR_CONNECTTYPE controls whether your application operates in a coordinated or uncoordinated distributed environment. To change the distributed environment in which your application operates, you set this attribute to one of the following values:
  • SQL_CONCURRENT_TRANS

    With this attribute value, the distributed environment is uncoordinated. Your application uses the semantics for a single data source for each transaction, as described in Conceptual view of a Db2 ODBC application. This value permits multiple (logical) concurrent connections to different data sources. SQL_CONCURRENT_TRANS is the default value for the SQL_ATTR_CONNECTTYPE environment attribute.

  • SQL_COORDINATED_TRANS

    With this attribute value, the distributed environment is coordinated. Your application uses semantics for multiple data sources per transaction, as this topic describes.

To use distributed units of work in your application, call SQLSetEnvAttr() or SQLSetConnectAttr() with the attribute SQL_ATTR_CONNECTTYPE set to SQL_COORDINATED_TRANS. You must set this attribute before you make a connection request.

All connections within an application must use the same connection type. You can set the connection type by using SQLSetEnvAttr(), SQLSetConnectAttr(), or the CONNECTTYPE keyword in the Db2 ODBC initialization file.

Recommendation: Set this environment attribute as soon as you successfully allocate an environment handle.