SQLCODE gets access violation
Posted in 2024
Rick Spagna's 32-bit application using CSDK 4.50.UC11 on Linux crashed with an access violation when reading SQLCODE after a connect, though the same code worked on Windows. Javier Sagrera noted SQLCODE is a global on Linux but a function on Windows. Solved by Rick: the Informix environment was not set up correctly; setting INFORMIXSERVER, ONCONFIG, INFORMIXSQLHOSTS, INFORMIXDIR and library paths fixed it.
Auto-generated by Claude from the posts below — may be imperfect; read the full thread.
Topics: Error Codes & Troubleshooting, Connectivity: ESQL/C, 4GL & Embedded SQL, Platform-Specific Issues
Hi, I'm using CSDK 4.50.UC.11 on Linux to access Informix 14.10 (64-bit) that is running on the same Linux VM. Here's the code: /* * EXEC SQL CONNECT TO :Did AS :Cid USER :Uid USING :Pid WITH CONCURRENT TRANSACTION; */ { ifx_conn_t *_sqiconn; _sqiconn = (ifx_conn_t *)ifx_alloc_conn_user(Uid, Pid); TRACE0(pThd,SL07, "Spagna: before connect_open"); sqli_connect_open(ESQLINTVERSION, 0, Did, Cid, _sqiconn, 1); TRACE0(pThd,SL07, "Spagna: after connect_open"); ifx_free_conn_user(&_sqiconn); TRACE0(pThd,SL07, "Spagna: after ifx_free_conn_user"); } TRACE0(pThd,SL07, "Spagna: before checking SQLCODE"); // Check for error if ( SQLCODE < 0 ) { TRACE0(pThd,SL07, "Spagna: ERROR: SQLCODE < 0!"); rc = SQLCODE; PST_GOTO_UNEXPECTED_RC(pThd,OpenConn,rc,"Connect_Error") } TRACE0(pThd,SL07, "Spagna: SQLCODE = 0!"); And here's what is in the log: Spagna: going to attempt to connect DSQLIFCN DSQLINFXOpenConnection (0819) SL07 08/16/2024 09:51:19 002037 00014C2D 00000056 Spagna: before connect_open DSQLIFCN DSQLINFXOpenConnection (0821) SL07 08/16/2024 09:51:19 002038 00014C2D 00000056 Spagna: after connect_open DSQLIFCN DSQLINFXOpenConnection (0823) SL07 08/16/2024 09:51:19 002039 00014C2D 00000056 Spagna: after ifx_free_conn_user DSQLIFCN DSQLINFXOpenConnection (0827) SL07 08/16/2024 09:51:19 002040 00014C2D 00000056 Spagna: before checking SQLCODE ERRLERRH ERR_RetryMgr (0293) EXCP 08/16/2024 09:51:19 002041 00014C2D 00000056 Win32 Exception=C0000005 at Address=00000000 Desc=Access Violation ERRLERRH ERR_RetryMgr (0000) ENVE 08/16/2024 09:51:19 002042 00014C2D 00000056 Exception:C0000005 (Access Violation) at (nil) I found the definition of SQLCODE: ./incl/esql/sqlca.h:#define SQLCODE (*(ifx_sqlcode())) I'd like to add that the same code, running on Windows using CSDK 4.50.FC11, works fine: Spagna: going to attempt to connect DSQCIFCN DSQLINFXOpenConnection (0812) SL07 08/16/2024 10:34:49 000290 00000840 00000F90 Spagna: before connect_open DSQCIFCN DSQLINFXOpenConnection (0814) SL07 08/16/2024 10:34:49 000291 00000840 00000F90 Spagna: after connect_open DSQCIFCN DSQLINFXOpenConnection (0816) SL07 08/16/2024 10:34:49 000292 00000840 00000F90 Spagna: after ifx_free_conn_user DSQCIFCN DSQLINFXOpenConnection (0821) SL07 08/16/2024 10:34:49 000293 00000840 00000F90 Spagna: before checking SQLCODE DSQCIFCN DSQLINFXOpenConnection (0829) SL07 08/16/2024 10:34:49 000294 00000840 00000F90 Spagna: SQLCODE = 0! Has anyone else ever encountered this and know what the solution is? Thanks! ------------------------------ Rick Spagna Optim Development Director UNICOM Global 973-755-4092 ------------------------------
I can't see anything wrong in your code (other than the TRACE lines, everything else what the ESQL/C pre-processor will generate) SQLCODE is different from Linux to Windows. informix@irk:/data/informix/IBM/14.10.FC10W2$ cc -g -I/data/informix/IBM/4.50.FC10W1/incl/esql -c conn2.c -E | grep SQLC extern int4 SQLCODE; printf("SQLCODE %d\\n",SQLCODE); informix@irk:/data/informix/IBM/14.10.FC10W2$ D:\\Infx\\work\\esql>grep sqlcode e.txt int4 sqlcode; int4 *(fnsqlcode()); printf("SQLCODE %d\\n",(*(fnsqlcode()))); D:\\Infx\\work\\esql> On Windows as the name implies is a function not just an external global variable. Can you clarify where are you seeing the exception? You mentioned that you are running Linux 4.50.UC11 on Linux (Why 32-bit?) but the exception in your output appears to be a Windows one: Win32 Exception=C0000005 at Address=00000000 Desc=Access Violation ------------------------------ Javier Sagrera ------------------------------
Hi Javier, The exception happens at this line: if ( SQLCODE < 0 ) as the trace above it ( Spagna: before checking SQLCODE) can be seen in the output, but the trace after it (either "ERROR: SQLCODE < 0!" or "SQLCODE = 0!") is not seen. I therefore believe it is SQLCODE that is causing the access violation. I am using 4.50 UC11 as my application (Optim) is 32-bit on Linux. The Win32 in the exception statement is a carry over from when the code base was originally written for Windows 32-bit. So, that is a message that is coming from our code that has not been updated. ------------------------------ Rick Spagna Optim Development Director UNICOM Global 973-755-4092 ------------------------------
I have figured out what the problem is. The environment where I run our code was not setup for Informix correctly. I had to add the following environment variables:
INFORMIXSERVER=opdvl3_i1410_1
ONCONFIG=onconfig.opdvl3_i1410_1
INFORMIXSQLHOSTS=/opt/IBM/Informix/etc/sqlhosts.opdvl3_i1410_1# Use CSDK 4.50
INFORMIXDIR=/opt/IBM/Informix.4.50.UC11# Use CSDK 4.10
#INFORMIXDIR=/opt/IBM/Informix.4.10.UC16
export LD_LIBRARY_PATH=$INFORMIXDIR/lib:$INFORMIXDIR/lib/esql:$LD_LIBRARY_PATH
export PATH=$INFORMIXDIR/bin:$INFORMIXDIR/lib:$INFORMIXDIR/esql:$PATHMy code then executed successfully!
------------------------------
Rick Spagna
Optim Development Director
UNICOM Global
973-755-4092
------------------------------
Maybe it was mixing libraries between CSDKS like the 'isqlt09b.so'. Anyway, glad to know that you got it working ;) ------------------------------ Javier Sagrera ------------------------------