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.
Procedure
The following methods 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 before 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);