ringerc/psqlODBC — pull request #2 by ringerc (2014-06-25 14:23:38+00:00)
Title: Fix driver name mismatch between 32-bit ODBC app and 64-bit MSDTC host

If the 32-bit driver runs on a 64-bit host within a 32-bit app
running under SysWow64 then XA transactions will fail to recover.

That's because recovery is done by pgxalib.dll which runs within
MSDTC.exe - a 64-bit application. It connects to a DSN supplied
by psqlODBC in EnlistInDtc_1pipe during DTC enlistment by the
XA resource manager. This DSN uses the driver name of the client's
ODBC driver - which is fine so long as the client and MSDTC
architectures match. If they don't then MSDTC will fail to connect
to Pg, so it'll never resolve transactions.

Traces of MSDTC will show RM_COMMIT_DELIVERY_FAILED_DUE_TO_CONNECTION_DOWN
events.

Traces of pgxalib.dll will show xa_recover(..) being entered, followed by
"SQLDriverConnect return=-1".

To fix this, we detect if we're running under SysWow64 by examining the
PROCESSOR_ARCHITEW6432 environment variable and supply the 64-bit driver name
if so.

See mailing list thread:

http://www.postgresql.org/message-id/53A45B59.70303@2ndquadrant.com

for details.