Hi,
Following is the program that connects to db2 database to fetch the records from a table. The program is compiled and linked without any errors on AIX 4.3.3 and with C++ compiler. But during execution it fails at SQLAllocHandle() while allocating environment handle.

The same program when compiled and linked on Windows in VC++ and executed, it works fine. The DB2 database is created on Windows environment.

No changes to database configuration is done.

Kindly give the inputs on db2 database configuration setting on AIX machine to use db2 CLI calls.


Sample program is as below

#include "iostream.h"
#include <sqlcli1.h>
#include "sqlext.h"
#include "stdio.h"
int allocEnv(SQLHANDLE*);
int allocConnect(SQLHENV,SQLHDBC*);
int freeConn(SQLHENV*,SQLHDBC*);
#define MAX_UID_LENGTH 18
#define MAX_PWD_LENGTH 30
#define MAX_CONNECTIONS 2
main()
{

SQLHANDLE henv;
SQLHDBC hdbc,hdbc1;
SQLHSTMT hstmt,hstmt1;
SQLCHAR * sqlstmt =
(unsigned char *)"SELECT distinct BGN_MP,END_MP,WORK_ORDER_ID from tactual_location where work_order_id in ('B230
06012380127701','B23006050061101402') " ;
struct test
{
SQLINTEGER ind ;
SQLDOUBLE MP ;
SQLCHAR ID[18];
} ;
struct test sBMP;
int error = allocEnv(&henv);
cout<<"Error in allocEnv"<<error<<endl;


// allocate a database handle for connection
if(!error)
error = allocConnect(henv,&hdbc);

// this will connect to eipms DNS configured on the machine.
if(error)
{
cout<<"Inside error"<<error<<endl;
freeConn(&henv,&hdbc);
return error;
}
if(!error)
error = allocConnect(henv,&hdbc1);

error = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ;
error = SQLAllocHandle( SQL_HANDLE_STMT, hdbc1, &hstmt1 ) ;
error = SQLExecDirect( hstmt, sqlstmt, SQL_NTS ) ;

error = SQLBindCol( hstmt, 1, SQL_C_DOUBLE, &sBMP.MP, 5, &sBMP.ind ) ;
error = SQLBindCol( hstmt, 2, SQL_C_DOUBLE, &sBMP.MP, 5, &sBMP.ind ) ;
error = SQLBindCol( hstmt, 3, SQL_CHAR, sBMP.ID, 19, &sBMP.ind ) ;
printf( "BMP-EMP Selected:\n" ) ;
printf( "BMP EMP ID\n" ) ;
printf( "-------------- ------------- ------------\n" ) ;
error = SQLExecute(hstmt);
char szTemp[50],szTemp1[50];
while ( ( error = SQLFetch( hstmt ) ) == SQL_SUCCESS )
{
printf( "%f %f %18s\n", sBMP.MP, sBMP.MP,sBMP.ID ) ;
}

/* Commit the changes. */
error = SQLEndTran( SQL_HANDLE_DBC, hdbc, SQL_COMMIT ) ;

error =SQLDisconnect(hdbc)&SQLFreeConnect(hdbc)&SQLFreeE nv(henv);
cout<<"Disconnected"<<endl;
return error;
}
allocEnv(SQLHANDLE *henv)
{
//if(SQLAllocEnv((long*)henv))
int error = 0;
if((error = SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,henv )) != 0)
{
cout<<"Error "<< error<<endl;
return -1;
}
else
return 0;
}
allocConnect(SQLHENV henv,SQLHDBC *hdbc)
{
if( SQLAllocConnect( henv,hdbc))
{
SQLFreeEnv(henv);
return -1;
}
SQLCHAR server[SQL_MAX_DSN_LENGTH + 1] ;
SQLCHAR uid[MAX_UID_LENGTH + 1] ;
SQLCHAR pwd[MAX_PWD_LENGTH + 1] ;
printf( "Enter DSN: " ) ;
gets( ( char * ) server ) ;
printf( "Enter User Name: " ) ;
gets( ( char * ) uid ) ;
printf( "Enter Password:" ) ;
gets( ( char * ) pwd ) ;
int error = SQLConnect( *hdbc , ( unsigned char * )server,SQL_NTS, ( unsigned char * )uid,SQL_NTS, ( unsigned ch
ar * )pwd,SQL_NTS);
if(error )
{
cout<<"Error in connection"<<endl;
}
return error;
}
freeConn(SQLHENV* henv,SQLHDBC* hdbc)
{
int error = SQLFreeConnect(*hdbc);
cout<<"Error1 "<<error<<endl;
error = SQLFreeEnv(*henv);
cout<<"Error2 "<<error<<endl;
error = SQLDisconnect(*hdbc);
cout<<"Error3 "<<error<<endl;
return error;
}