The minimum supported level of DB2 is DB2 Universal Database(R), Version 5.0.
You need to do the following:
Ensure that your DB2 environment variables are set for queue manager processes as well as in your application processes. In particular, you must always set the DB2INSTANCE environment variable before you start the queue manager. The DB2INSTANCE environment variable identifies the DB2 instance containing the DB2 databases that are being updated.
The easiest way to create the DB2 switch load file is to use the sample file xaswit.mak. The source code used to create the DB2 switch on most platforms is shown in Figure 11. The source for db2swit.c for Windows systems is different; it is shown in Figure 12.
Figure 11. Source code for db2swit.c for UNIX systems
#include <cmqc.h> #include "xa.h" extern struct xa_switch_t db2xa_switch; struct xa_switch_t * MQENTRY MQStart(void) { return(&db2xa_switch); } |
Figure 12. Source code for db2swit.c on Windows systems (Microsoft Visual C++-specific)
#include <cmqc.h> #include "xa.h" extern __declspec(dllimport) struct xa_switch_t db2xa_switch; struct xa_switch_t * MQENTRY MQStart(void) { return(&db2xa_switch); } |
The xa.h header file supplied with WebSphere MQ is installed (for WebSphere MQ for Windows) in the C:\Program Files\IBM\WebSphere MQ\tools\c\samples\xatm directory, or (for WebSphere MQ for UNIX systems) in the /opt/mqm/samp/xatm directory (/usr/mqm/samp/xatm for AIX).
To create the DB2 switch load file on Windows systems, compile db2swit.c and link it against db2api.lib. The DEF file shown in Figure 13 is needed to produce the DLL:
Figure 13. Source code for db2swit.def on Windows systems
LIBRARY DB2SWIT EXPORTS MQStart |
To create the DLL:
Figure 14. Makefile for DB2 switch on Windows systems
!include <ntwin32.mak> db2swit.lib db2swit.exp: $*.obj $*.def $(implib) -machine:$(CPU) \ -def:$*.def $*.obj db2swit.dll: $*.obj $*.def $*.exp $(link) $(dlllflags) \ -base:0x1C000000 \ $*.exp $*.obj \ $(conlibsdll) db2api.lib .c.obj: $(cc) $(cflags) $(cvarsdll) $*.c |
nmake /f xaswit.mak db2swit.dll
nmake /f xaswiti.mak db2swit.dll
WebSphere MQ provides a sample makefile, xaswit.mak, to build the switch files for a variety of database products. You can find xaswit.mak in the directory /usr/mqm/samp/xatm, with the source files you need to build the switch.
Edit xaswit.mak to uncomment the lines appropriate to the version of DB2 you are using. Then execute the makefile using the command:
make -f xaswit.mak db2swit
The generated switch file is placed in your current directory.
The next step is to modify the configuration information for the queue manager to define DB2 as a participant in global units of work. On Windows systems, use the Resources page of the properties for the queue manager (accessed from the WebSphere MQ Services snap-in). On WebSphere MQ for UNIX systems, use the XAResourceManager stanza of the qm.ini configuration file.
See XA resource managers for a more detailed description of XA resource manager configuration information.
database_alias<,username,password>
where database_alias is the name of the database, unless you have explicitly cataloged an alias name after creating the database, in which case specify the alias instead.
The other parameters are optional. They provide alternative authentication information to the database if it was set up with authentication=server.
See Security considerations for more information about security.
For fuller descriptions of each of these attributes, see "XA resource managers".
Figure 15 shows some sample XAResourceManager entries where the database to be updated is called MQBankDB, this name being specified as the XAOpenString.
Figure 15. Sample XAResourceManager entry for DB2 on Windows systems
XAResourceManager: Name=DB2 MQBankDB SwitchFile=c:\user\dll\db2swit.dll XAOpenString=MQBankDB ThreadOfControl=PROCESS |
Figure 16 is a UNIX sample. It assumes that the DB2 switch load file is copied to the /usr/bin directory being created:
Figure 16. Sample XAResourceManager entry for DB2 on UNIX platforms
XAResourceManager: Name=DB2 MQBankDB SwitchFile=/usr/bin/db2swit XAOpenString=MQBankDB |
For each DB2 database that the queue manager is coordinating, you need to:
For example, to give the mqm user ID connect authority to the MQBankDB database, use the following commands:
Figure 17. Sample commands to give connect user ID authority to MQBANKDB
db2 connect to MQBankDB db2 grant connect on database to user mqm |
See Security considerations for more information about security.
Use the command db2 update dbm cfg using TP_MON_NAME mqmax to name MQMAX.DLL as the library that DB2 uses to call the queue manager. This must be present in a directory within PATH.
DB2 does not allow user names of more than eight characters. This means that you cannot use WebSphere MQ services (for example, the WebSphere MQ Services snap-in) to start a queue manager that has DB2 defined as a resource manager if WebSphere MQ services is using the default user name set up by WebSphere MQ (MUSR_MQADMIN). This might cause message AMQ7604 to be written to the queue manager error log and SQLCODEs -1046 and -998 (reason code 2) to be written to the DB2 log file db2diag.log
If you want to use WebSphere MQ services in these circumstances, you must either:
Alternatively, you can start the queue manager from the command line, using the strmqm command with a user name of eight characters or fewer.