У меня проблема с использованием pyodbc
для подключения в MS Access
Несколько дней назад я нормально работал с моей системой, но когда я обновился, моя Anaconda начала поднимать эта ошибка.
Мой код ниже:
import pyodbc
def conn_cur_access_db(path, base):
access_conn_str = "DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ={}{}".format(path,base)
print(access_conn_str)
conn = pyodbc.connect(access_conn_str)
cur = conn.cursor()
return conn, cur
path = r"G:\my\db\path"
base = "mydb.accdb"
conn, cur = conn_cur_access_db(path, base)
# do something
conn.close()
cur.close()
del conn
del cur
В моем первом соединении это работает, но когда я пытаюсь установить больше соединений, я получаю следующий Tracerback:
<ipython-input-1-827e414c3c0e> in conn_cur_access_db(path, base)
4 access_conn_str = "DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ={}{}".format(path,base)
5 print(access_conn_str)
----> 6 conn = pyodbc.connect(access_conn_str)
7
8 return conn
Error: ('HY000', 'The driver did not supply an error!')
Я искал в inte rnet об этой ошибке, но я не нашел ничего о моей проблеме с MS Access
ОБНОВЛЕНИЕ
У меня есть сделал тест
for i in range(10):
try:
conn, cur = conn_cur_access_db(path, base)
with conn:
with cur:
print("A")
print(conn, cur)
except Exception as e:
print(e)
conn, cur = conn_cur_access_db(path, base)
with conn:
with cur:
print("B")
print(conn, cur)
и результат:
A
<pyodbc.Connection object at 0x0000016000C1E030> <pyodbc.Cursor object at 0x0000016000C181B0>
A
<pyodbc.Connection object at 0x0000016000C1E100> <pyodbc.Cursor object at 0x0000016000C182B0>
('HY000', 'The driver did not supply an error!')
B
<pyodbc.Connection object at 0x0000016000C1E030> <pyodbc.Cursor object at 0x0000016000C18230>
('HY000', 'The driver did not supply an error!')
B
<pyodbc.Connection object at 0x0000016000C1E100> <pyodbc.Cursor object at 0x0000016000C18330>
('HY000', 'The driver did not supply an error!')
B
<pyodbc.Connection object at 0x0000016000C1E030> <pyodbc.Cursor object at 0x0000016000C182B0>
('HY000', 'The driver did not supply an error!')
B
<pyodbc.Connection object at 0x0000016000C1E100> <pyodbc.Cursor object at 0x0000016000C181B0>
('HY000', 'The driver did not supply an error!')
B
<pyodbc.Connection object at 0x0000016000C1E030> <pyodbc.Cursor object at 0x0000016000C18330>
('HY000', 'The driver did not supply an error!')
B
<pyodbc.Connection object at 0x0000016000C1E100> <pyodbc.Cursor object at 0x0000016000C18230>
('HY000', 'The driver did not supply an error!')
B
<pyodbc.Connection object at 0x0000016000C1E030> <pyodbc.Cursor object at 0x0000016000C181B0>
('HY000', 'The driver did not supply an error!')
B
<pyodbc.Connection object at 0x0000016000C1E100> <pyodbc.Cursor object at 0x0000016000C182B0>