Need help on connecting to DB2 from Python using ibm_db module.
I have CentOS 5.4 and Python 2.6. I installed DB2 Express-C 9.7.1,
then checked out ibm_db module sources (is there an egg for Python
2.6?), built and installed it. I also added /opt/ibm/db2/V9.7/lib32 in
LD_LIBRARY_PATH.
In general, everything is fine. I made a new database, and then I can
establish a connection, create a table, insert and select data using
Python program.
But any SELECT from sysibm.sysdummy1 table doesn't work.
I tried to execute "select 'Hello, World!' from sysibm.sysdummy1". It
works from native DB2 client. But Python script fails with the
following error:
---
Traceback (most recent call last):
File "sysdummy.py", line 7, in <module>
cursor.execute("select 'Hello, World!' from sysibm.sysdummy1")
File "/usr/local/py26/lib/python2.6/site-packages/ibm_db-1.0-py2.6-
linux-i686.egg/ibm_db_dbi.py", line 1141, in execute
self._execute_helper(None, parameters)
File "/usr/local/py26/lib/python2.6/site-packages/ibm_db-1.0-py2.6-
linux-i686.egg/ibm_db_dbi.py", line 1071, in _execute_helper
raise _get_exception(inst)
ibm_db_dbi.ProgrammingError: ibm_db_dbi::ProgrammingError: Statement
Execute Failed: [IBM][CLI Driver] SQL1224N The database manager is
not able to accept new requests, has terminated all requests in
progress, or has terminated the specified request because of an error
or a forced interrupt. SQLSTATE=55032 SQLCODE=-1224
---
Here is my Python example:
---
import ibm_db
ibm_db_conn = ibm_db.connect('test', 'db2inst1', 'prometeus')
import ibm_db_dbi
conn = ibm_db_dbi.Connection(ibm_db_conn)
cursor = conn.cursor()
cursor.execute("select 'Hello, World!' from sysibm.sysdummy1")
row = cursor.fetchone()
print row
conn.close()
---
I hope there is an obvious mistake and somebody will point me to it :)
Thanks,
Andrey
You are not doing anything wrong in your code.
You got this error due to any of the following causes :
1) The database manager was stopped.
2) The database agent was forced off by the system administrator.
3) The database agent was terminated due to an abnormal
termination of a key database manager process.
For more detail information about this error, refer following link
http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=/com.ibm.db2.luw.messages.sql.doc/doc/msql01224n.html
Thanks,
Rahul Priyadarshi
Thank you, I've read the error description. It recommends to tune the
database server or improve the client application if it might take too
much resources...
The problem is that the same query works fine from the command line
processor:
---
db2 => connect to test
Database Connection Information
Database server = DB2/LINUX 9.7.1
SQL authorization ID = DB2INST1
Local database alias = TEST
db2 => select 'Hello, World!' from sysibm.sysdummy1
1
-------------
Hello, World!
1 record(s) selected.
---
So, most of information in the documentation is useless because I use
the same instance and same database for executing my query both from
Python and from command line processor.
The instance works fine. All queries work fine from the command line
processor. So, there is no need to fix the database server itself as
the article you mention recommends to do.
I believe that something is wrong with the ibm_db module in Python. I
probably need to adjust something in the Python connectivity module.
Thanks,
Andrey
On Mar 12, 5:02 pm, Rahul <rahul.priyadar...@in.ibm.com> wrote:
> Hi Andrey,
>
> You are not doing anything wrong in your code.
> You got this error due to any of the following causes :
> 1) The database manager was stopped.
> 2) The database agent was forced off by the system administrator.
> 3) The database agent was terminated due to an abnormal
> termination of a key database manager process.
> For more detail information about this error, refer following linkhttp://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=...
Thanks,
Rahul Priyadarshi
Thanks,
Andrey
Thanks,
Rahul Priyadarshi
For instance, I have the following example (I named it db2.py) and it
runs successfully.
Source:
---
import ibm_db
ibm_db_conn = ibm_db.connect('test', 'db2inst1', '***')
import ibm_db_dbi
conn = ibm_db_dbi.Connection(ibm_db_conn)
conn.tables('SYSCAT', '%')
cursor = conn.cursor()
cursor.execute("DROP TABLE test")
cursor.execute("CREATE TABLE test (f varchar(50))")
cursor.execute("INSERT INTO test VALUES ('Hello, World!')")
cursor.execute("SELECT * FROM test")
row = cursor.fetchone()
print row
conn.close()
---
Result:
---
[db2inst1@regress ~]$ python db2.py
/usr/local/py26/lib/python2.6/site-packages/ibm_db-1.0-py2.6-linux-
i686.egg/ibm_db_dbi.py:25: DeprecationWarning: the sets module is
deprecated
from sets import ImmutableSet
(u'Hello, World!',)
---
Thanks,
Andrey
Thanks,
Rahul Priyadarshi
This error comes not due to ibm_db module. Actually this is an issue
of CLI in Express-C edition.
This one is reproducible through following CLI script
----
opt echo on
quickc 1 1 test
sqlallocstmt 1 1
sqlsetstmtoption 1 sql_attr_cursor_type 3
sqlexecdirect 1 "select 'Hello, World!' from sysibm.sysdummy1" -3
sqlgetdiagrec SQL_HANDLE_STMT 1 1
fetchall 1
sqltransact 1 1 SQL_ROLLBACK
killenv 1
------
I am raising a defect for this issue on DB2 CLI. I will update you
about this when it get solved.
Is this issue blocking your application or you are using this as a
testing purpose. If this one is blocking your application then i will
give you some workaround.
Thanks,
Rahul Priyadarshi
Thank you for your help!
I'm doing some investigations for our application and preparing a test
bed. DB2 is going to be next DBMS the product will support.
Right now we are not blocked. But we will start working on DB2 support
next month or in two months. Do you expect that the defect will be
fixed soon? If not, a workaround will be very appreciated.
Thanks,
Andrey
Thanks,
Rahul Priyadarshi
I have created a patch to increase performance of dbi wrapper. This
patch will be able to solve your problem also.
Because your reported bug arises only when we execute “select 'Hello,
World!' from sysibm.sysdummy1” type of query after setting cursor
attribute to static.
In this patch we are not setting cursor attribute to static by
default. So, now your query will work fine.
The modified patch of dbi is attached on
http://groups.google.com/group/ibm_db/browse_thread/thread/2f6bdffa68524ce1
discussion thread. You can download it from there and replace the
existing ibm_db_dbi.py with this one(at location “../site-packages/
ibm_db.py2.x-xxx.egg/”).
Give it a try and let me know hows it works.
Thanks,
Rahul Priyadarshi