This article describes how to run a Gen C/DB2 Window Packaged (GUI) application using Windows logon authentication to DB2 instead of the default method which prompts for DB2 login credentials stored in the iefgdic.ini file (see Testing and Running Applications for Windows IT section "Global Database Information Container for GUI").
The default method always prompts for DB2 credentials at runtime because the DB2 password is not stored in the iefgdic.ini file but also manually editing the file to store the password in plain text would be a security risk.
Using DB2 Windows logon authentication when running the GUI application is not as straightforward as it is for the Build Tool DB2 connection documented in article: Gen Build Tool DB2 connection using Windows logon (OPT.DBPSWD plain text))
The default DB2 database stub source STUBDB2N.SQC (used for STUBDB2N.OBJ in a GUI DB2 application build) expects a userid and password value to be present in the iefgdic.ini file when it reads the file i.e. it only contains this EXEC SQL CONNECT statement:
EXEC SQL CONNECT TO :Database USER :Uid USING :Passwd ;
However the STUBDB2N.SQC can be recoded and recompiled to build a new STUBDB2N.OBJ which will enable Windows logon authentication.
Gen 8.6 with latest PTFs applied.
int ret;
EXEC SQL CONNECT TO :Database USER :Uid USING :Passwd ;
EXEC SQL CONNECT TO
:Database;
#define DATABASE_LEN 30
char Database[DATABASE_LEN]; // vuln fix
char Database[30]; // vuln fix
strcpy_s(Database, DATABASE_LEN, szDatabase); // vuln fix
strcpy_s(Database, 30, szDatabase); // vuln fix
See attached copy of the modified file STUBDB2N.SQC for easy reference.
set DBPATH=C:\Program Files\IBM\SQLLIB
set LIB=C:\Program Files\IBM\SQLLIB\lib\Win32;%LIB%
set AEDB=GENDB
set AEUSER=db2user
set AEPASSWORD=db2password
nmake -nologo -s -f stubdb2n.mak all
cd %Gen86%\Gen
genenv 32 2019
(sets the Visual Studio environment - this is example is for Visual Studio 2019)build_stubdb2n.cmd