为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【版本】:
数据库版本:dm8
python 3.7
lib dmPython-8.1.2.98
【操作系统】:Windows
【问题描述】*:在用python开发时,一个循环中多次连接达梦数据库,第二次就会出现连接异常,代码如下:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import dmPython as dm
for i in range(10):
print('........', i)
conn = dm.connect('SYSDBA/SYSDBA001@127.0.0.1:5236', autoCommit=True)
cursor = conn.cursor()
cursor.execute("select COUNT(1) from T_SYS_ROLE")
a = cursor.fetchone()[0]
cursor.close()
conn.close()
print("sys_menu count:", a)
运行结果如下:
........ 0
sys_menu count: 0
........ 1
dmPython.DatabaseError: [CODE:-2501]用户名或密码错误
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:/py-project/webpy/IteratorDm.py", line 7, in <module>
conn = dm.connect('SYSDBA/SYSDBA001@127.0.0.1:5236', autoCommit=True)
SystemError: <class 'dmPython.Connection'> returned a result with an error set
从日志中可以看出,第一次是连接并查询成功,第二次开始循环
如果改成一次连接呢?你这样频繁的连库性能也不好