4

odbc.ini:

[DEFAULT]
Driver          = DB2
[abc]
Driver          = DB2
[dsn_test1]
DESCRIPTION = Connection to DB2
Driver          = db2

odbcinst.ini:

[DB2]
Description = DB2 Driver
Driver = /home/user/sqllib/lib/libdb2.so
fileusage=1
dontdlclose=1

[ODBC]
Trace=1
TraceFile=/home/user/sqllib/trace.out

db2cli.ini

[abc]
hostname="hostname"
pwd="passwd"
port="port"
PROTOCOL=TCPIP
database="dbname"
uid="uid"

$ ./isql abc

+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+

while connecting from db2 driver,below error is coming:

Connection attempt for data source name "abc":
===============================================================================
ODBC Driver Manager Path: /home/user/sqllib/odbclib/lib/libodbc.so

[FAILED]: [unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV 
failed

Below is the snippet of odbc trace:

[ODBC][23419][1403783774.660159][SQLConnect.c][1380]Error: IM004
[ODBC][23419][1403783774.660223][SQLError.c][434]
    Entry:
        Connection = 0x81aaac8
        SQLState = 0xffff9593
        Native = 0xffff9684
        Message Text = 0xffff8d93
        Buffer Length = 1024
        Text Len Ptr = 0xffff95bc
[ODBC][23419][1403783774.660260][SQLError.c][471]
    Exit:[SQL_SUCCESS]
        SQLState = IM004
        Native = 0xffff9684 -> 0
        Message Text = [[unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed]

Googled a lot for root-cause,dint helped much,please provide some pointer to solve this. its a 32 bit linux machine having 32 bit db driver as well.

Anand
  • 621
  • 3
  • 9
  • 31

1 Answers1

2

According to this IBM Support page, an IM004 SQLState on SQLAllocHandle relates to the new security feature.

Cause

The new security features introduced in DB2® Universal Database™ (DB2 UDB) Version 8.2 prevent users from using the database unless they belong to the Windows® groups DB2ADMNS or DB2USERS.

Answer

Add the userid (the one used to execute the application) to either the DB2ADMNS or DB2USERS group. Please refer to the link under "Related Information" (below) for instructions on how to accomplish this.

Alternatively, there are a number of threads (e.g. Huge problems connecting to a DB2 database) which suggest setting the DB2INSTANCE environment variable to match the instance setting in your odbc.ini file for the DSN concerned, e.g.

export DB2INSTANCE=db2inst1
isql -v FS01DB2
kenorb
  • 155,785
  • 88
  • 678
  • 743
mc110
  • 2,825
  • 5
  • 20
  • 21
  • 1
    Hi,thanks for reply,forgot to mention its linux32 bit machine and instanceless client.DB2INSTANCE wont be effective in this case – Anand Jun 27 '14 at 08:23
  • 1
    have you tried looking at their site for instructions on building from source (and then being able to modify). It's been a while but I did that in the past when working on an ODBC driver. – mc110 Jun 30 '14 at 07:56
  • export CC=gcc export CFLAGS="-maix64 -q64 -DBUILD_REAL_64_BIT_MODE" export OBJECT_MODE=64 ,debug after this seeting on linux – Anand Jul 06 '14 at 07:12
  • Edit your question to answer (1) what is the Linux distro and version detail (2) what is the installed Db2-driver name and type, and especially its version, fixpack (3) Detail what you mean by "connecting from Db2 driver", show the exact command line (if using) or the source-code. (4) Detail the account(s) involved, i.e. which account has the Db2-driver installed, and which account is attempting to connect via which method. – mao Oct 10 '17 at 06:21