错误:(“ IM005”,“ [IM005] [unixODBC] [驱动程序管理器] SQL_HANDLE_DBC上的驱动程序的SQLAllocHandle失败(0)(SQLDriverConnect)”) [英] Error: ('IM005', "[IM005] [unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_DBC failed (0) (SQLDriverConnect)")
问题描述
我正在我的pyodbc脚本中运行此代码,尝试在其中执行并行操作
I am running this code in my pyodbc script where I am trying to do parallelism
templst = [lineitem, orders, partsupp, region, cur_cur, T1, T2]
connstr = [DRIVER={libdbodbc17.so};host=lint16muthab.phl.sap.corp:8766;UID=dba;PWD=sql;CharSet=utf8, DRIVER={libdbodbc17.so};host=localhost:8767;UID=dba;PWD=sql;CharSet=utf8,
DRIVER={libdbodbc17.so};host=localhost:8768;UID=dba;PWD=sql;CharSet=utf8,
DRIVER={libdbodbc17.so};host=localhost:8769;UID=dba;PWD=sql;CharSet=utf8, DRIVER={libdbodbc17.so};host=localhost:8770;UID=dba;PWD=sql;CharSet=utf8]
def extract_single(q, cursorconn):
while True:
try:
tableName = q.get_nowait()
time.sleep(3)
qry2 = "Select * FROM %s"% (tableName)
print " extraction done of table:%s done by cursor:%s"%(tableName,cursorconn)
except Queue.Empty:
return
def main():
q = multiprocessing.Queue()
for item in templst:
q.put(item) # add items to queue
process = []
for i in xrange(5):
p = multiprocessing.Process(target=extract_single, args=(q, connstr[i]))
process.append(p)
p.start()
for p in process:
p.join()
if __name__ == '__main__':
main()
输出类似于:
extraction done of table:lineitem done by cursor:DRIVER={libdbodbc17.so};host=lint16muthab.phl.sap.corp:8766;UID=dba;PWD=sql;CharSet=utf8
表提取:光标完成的命令:DRIVER = {libdbodbc17.so}; host = localhost:8767; UID = dba; PWD = sql; CharSet = utf8
extraction done of table:orders done by cursor:DRIVER={libdbodbc17.so};host=localhost:8767;UID=dba;PWD=sql;CharSet=utf8
extraction done of table:partsupp done by cursor:DRIVER={libdbodbc17.so};host=localhost:8768;UID=dba;PWD=sql;CharSet=utf8
extraction done of table:region done by cursor:DRIVER={libdbodbc17.so};host=localhost:8769;UID=dba;PWD=sql;CharSet=utf8
extraction done of table:cur_cur done by cursor:DRIVER={libdbodbc17.so};host=localhost:8770;UID=dba;PWD=sql;CharSet=utf8
extraction done of table:T2 done by cursor:DRIVER={libdbodbc17.so};host=localhost:8767;UID=dba;PWD=sql;CharSet=utf8
extraction done of table:T1 done by cursor:DRIVER={libdbodbc17.so};host=lint16muthab.phl.sap.corp:8766;UID=dba;PWD=sql;CharSet=utf8
但是当我将提取函数修改为
But when I modify my extract function into
def extract_single(q, cursorconn):
while True:
try:
tableName = q.get_nowait()
time.sleep(3)
conn = pyodbc.connect(cursorconn, timeout=0)
cursor = connvar.cursor()
qry2 = "Select * FROM %s"% (tableName)
cursor.execute(qry2).fetchall()
print " extraction done of table:%s done by cursor:%s"%(tableName,cursorconn)
except Queue.Empty:
return
我遇到错误,无法打开连接和光标,因此我可以执行此查询并将数据转储到文件中。
I am getting error and not able to open a connection and cursor on that so that I can execute this query and dump data into files.
2Process Process-1:
Traceback (most recent call last):
File "/sybopt/software/python/python/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/sybopt/software/python/python/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "conn3.py", line 86, in extract_single
Process Process-2:
Traceback (most recent call last):
connvar = pyodbc.connect(cursorconn, timeout=0)
File "/sybopt/software/python/python/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
Error: ('IM005', "[IM005] [unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_DBC failed (0) (SQLDriverConnect)")
self.run()
File "/sybopt/software/python/python/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "conn3.py", line 86, in extract_single
connvar = pyodbc.connect(cursorconn, timeout=0)
Error: ('IM005', "[IM005] [unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_DBC failed (0) (SQLDriverConnect)")
Process Process-3:
Traceback (most recent call last):
File "/sybopt/software/python/python/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/sybopt/software/python/python/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "conn3.py", line 86, in extract_single
connvar = pyodbc.connect(cursorconn, timeout=0)
适用于所有连接。请让我知道如何解决此错误。
使用游标对象时出错
for all connections. Please let me know how to resolve this error. Error getting while using cursor object
我想使用以列表形式存储的游标对象,而不是打开重新建立新连接,每次打开游标。
游标列表看起来像
I want to use cursor object which I have stored in a form of list instead of opening a new connection again and everytime open a cursor. cursorlist will look like
<pyodbc.Cursor object at 0x7fcd9b47f270> <pyodbc.Cursor object at 0x7fcd9b47f330> <pyodbc.Cursor object at 0x7fcd9b47f390> <pyodbc.Cursor object at 0x7fcd9b47f3f0> <pyodbc.Cursor object at 0x7fcd9b47f450>
所以我有5个光标对象
,表列表与上面相同
So I have 5 cursor objects and table list same as above
def extract_single(q, cursorconn):
while True:
try:
tableName = q.get_nowait()
qry2 = "Select count(*) FROM %s"%(tableName)
cursorconn.execute(qry2)
rowcnt = cursorconn.fetchone()[0]
print " rows in tempdsc=",rowcnt
print " extraction done of table:%s done by cursor:%s"%(tableName,cursorconn)
except Queue.Empty:
return
def main():
q = multiprocessing.Queue()
for item in tempdsclst:
q.put(item) # add items to queue
process = []
for i in xrange(5):
p = multiprocessing.Process(target=extract_single, args=(q, curlst[i]))
process.append(p)
p.start()
for p in process:
p.join()
它会给出类似
Process Process-1:
Traceback (most recent call last):
File "/sybopt/software/python/python/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
Process Process-2:
Traceback (most recent call last):
self.run()
File "/sybopt/software/python/python/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
File "/sybopt/software/python/python/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "conn4.py", line 87, in extract_single
cursorconn.execute(qry2)
Error: ('HY000', 'The driver did not supply an error!')
self.run()
File "/sybopt/software/python/python/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "conn4.py", line 87, in extract_single
cursorconn.execute(qry2)
Error: ('HY000', 'The driver did not supply an error!')
Process Process-3:
Traceback (most recent call last):
File "/sybopt/software/python/python/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/sybopt/software/python/python/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "conn4.py", line 87, in extract_single
cursorconn.execute(qry2)
Error: ('HY000', 'The driver did not supply an error!')
Process Process-4:
Traceback (most recent call last):
File "/sybopt/software/python/python/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/sybopt/software/python/python/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "conn4.py", line 87, in extract_single
cursorconn.execute(qry2)
Error: ('HY000', 'The driver did not supply an error!')
Process Process-5:
Traceback (most recent call last):
File "/sybopt/software/python/python/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/sybopt/software/python/python/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "conn4.py", line 87, in extract_single
cursorconn.execute(qry2)
Error: ('HY000', 'The driver did not supply an error!')
推荐答案
除了您遇到的问题外,根据您之前的问题,我还假设 cursorconn
是一个已经打开的连接,可以在每个查询中重复使用。由于它现在似乎只是一个连接字符串(尽管在您的代码中它似乎不是一个实际的字符串,这与列表 templst
中的项目的情况相同) ???),那么您应该拨打 conn = pyodbc.connect(cursorconn,timeout = 0)
之前 c> while True:语句,以便同一连接可以重用于多个查询,然后在从函数返回之前应关闭该连接。
Aside from the problem you are having, based on your earlier question I had assumed that cursorconn
was an already opened connection that would be reused for each query. Since it now appears to be just a connection string (although in your code it doesn't seem to be an actual string, which is the same situation for the items in list templst
???), then you should be making the call conn = pyodbc.connect(cursorconn, timeout=0)
before the while True:
statement so that the same connection can be reused for multiple queries and you should then close the connection before you return from the function.
我认为问题在于语句 cursor = connvar.cursor()
,它应该是: cursor = conn.cursor()
。因此,尝试以下操作:
I think the problem is the statement cursor = connvar.cursor()
, which should be: cursor = conn.cursor()
. So, try the following:
conn = pyodbc.connect(cursorconn, timeout=0)
while True:
try:
tableName = q.get_nowait()
time.sleep(3) # why is this here?
cursor = conn.cursor()
qry2 = "Select * FROM %s"% (tableName)
cursor.execute(qry2).fetchall()
print " extraction done of table:%s done by cursor:%s"%(tableName,cursorconn)
cursor.close() # should probably add this
except Queue.Empty:
return
finally:
conn.close()
这篇关于错误:(“ IM005”,“ [IM005] [unixODBC] [驱动程序管理器] SQL_HANDLE_DBC上的驱动程序的SQLAllocHandle失败(0)(SQLDriverConnect)”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!