注册

dmpython第二次连接达梦集群报错

fhshen 2023/02/14 855 3

使用dmpython连接达梦集群数据库,首次连接可以查询并成功返回,再次连接时,再也连接不上了。

写了一个连接类

import dmPython import traceback class DaMengDBClient: def __init__(self, host, user, pwd): self.host = host self.user = user self.pwd = pwd self.collectionstrurl = "%s/%s@%s" % (self.user, self.pwd, self.host) def __enter__(self): try: self.cnxn = dmPython.connect(self.collectionstrurl) self.cursor = self.cnxn.cursor() return self except Exception as e: print(e) print('数据库连接失败!') print(traceback.format_exc()) def __exit__(self, exc_type, exc_val, exc_tb): self.cursor.close() self.cnxn.close() if __name__ == '__main__': host = 'DamengDSC' user = 'test' pwd = '123456' with DaMengDBClient(host=host, user=user, pwd=pwd) as oc: sql = 'select * from "test"' # 执行SQL语句 values = oc.cursor.execute(sql).fetchall() print(values)

第一次成功后,第二次
报错:[-70028]:创建 SOCKET 连接失败

回答 0
暂无回答
扫一扫
联系客服