By default, CLI applications
running on Windows systems
make use of the default DB2® copy.
However, applications can use any DB2 copy
that is installed on the system.
Before you begin
Ensure your Windows
CLI environment
is set up.
Procedure
The following are different methods that allow CLI applications
to successfully access a different DB2 copy
on Windows operating systems:
- Using the DB2 command
window from the : the command window is already set up with the correct
environment variables for the particular DB2 copy
chosen.
- Using db2envar.bat from a command
window:
- Open a command window.
- Run the db2envar.bat file using the fully
qualified path for the DB2 copy
that you want the application to use:
DB2_Copy_install_dir\bin\db2envar.bat
- Run the CLI application
from the same command window.
This will set up all the environment variables for the selected DB2 copy in the command window where
the db2envar.bat was run. Once the command window
has been closed and a new one opened, the CLI application
will run against the default DB2 Copy
unless the db2envar.bat for another DB2 copy is run again.
- Using the db2SelectDB2Copy API: For
applications that are dynamically linked, you can call this API prior
to loading any DB2 DLLs within
your application process. This API sets up the required environment
for your application to use the DB2 copy
that you want to use. The /delayload linking
option can be used to delay the loading of any DB2 DLL. For example, if your CLI application
links db2api.lib, then you must use the /delayload option
of your linker to delay the load db2app.dll:
cl -Zi -MDd -Tp App.C /link /DELAY:nobind /DELAYLOAD:db2app.dll
advapi32.lib psapi.lib db2api.lib delayimp.lib
To use the API, you will need to include db2ApiInstall.h,
which will force your application to statically link in db2ApiInstall.lib.
- Using LoadLibraryEx: Instead of using LoadLibrary, you
can call LoadLibraryEx with the LOAD_WITH_ALTERED_SEARCH_PATH parameter
to load the db2app.dll that corresponds to the
version of the DB2 copy you
want to use. For example:
HMODULE hLib = LoadLibraryEx("c:\\sqllib\\bin\\db2app.dll",
NULL, LOAD_WITH_ALTERED_SEARCH_PATH);