Building C/C++ multi-connection applications on Windows
You can use the provided build scripts to compile and link C and C++ embedded SQL and Db2® API programs. The scripts are in the sqllib\samples\c and sqllib\samples\cpp directories. The directories also contain sample programs that you can build with these files.
You can find the commands to build a Db2 multi-connection program in the bldmc.bat batch file. The commands require two databases. The compile and link options are the same as those used in the bldapp.bat file.
About this task
%1
, specifies the
name of your source file. The second parameter, %2
,
specifies the name of the first database to which you want to connect.
The third parameter, %3
, specifies the second database
to which you want to connect. These are all required parameters. %2
and %3
) so
if you are using the build script, and accept these defaults, you
only have to specify the program name (the %1
parameter).
If you are using the bldmc.bat
script, you must specify
all three parameters.Optional parameters are not required
for a local connection, but are required for connecting to a server
from a remote client. These are: %4
and %5
to
specify the user ID and password, for the first database; and %6
and %7
to
specify the user ID and password, for the second database.
For the multi-connection sample program, dbmcon.exe, you require two
databases. If the sample
database is not yet created, you can create it by entering
db2sampl
on the command line of a Db2 command window. The
second database, here called sample2
, can be created with one of the following
commands:
db2 create db sample2
If
creating the database remotely: db2 attach to node_name
db2 create db sample2
db2 detach
db2 catalog db sample2 as sample2 at node node_name
where node_name is
the node where the database resides. Multi-connection also requires that the TCP/IP listener is running.
Procedure
To ensure that the TCP/IP listener is running:
Results
dbmcon.sqc
ordbmcon.sqx
- Main source file for connecting to both databases.
dbmcon1.sqc
ordbmcon1.sqx
- Source file for creating a package bound to the first database.
dbmcon1.h
- Header file for dbmcon1.sqc or dbmcon1.sqx included in the main source file, dbmcon.sqc or dbmcon.sqx, for accessing the SQL statements for creating and dropping a table bound to the first database.
dbmcon2.sqc
ordbmcon2.sqx
- Source file for creating a package bound to the second database.
dbmcon2.h
- Header file for dbmcon2.sqc or dbmcon2.sqx included in the main source file, dbmcon.sqc or dbmcon.sqx, for accessing the SQL statements for creating and dropping a table bound to the second database.
bldmc dbmcon sample sample2
The
result is an executable file, dbmcon.exe. dbmcon
The program demonstrates a one-phase commit to two databases.