Estou com um certo problema em utilizar o pyodbc
para conectar em um MS Access.
Até poucos dias atrás, estava tudo operando normalmente, porém após a atualização do meu Anaconda, passou a ocorrer um erro persistente no sistema.
Error: ('HY000', 'The driver did not supply an error!')
No caso, segue um trecho do código:
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
#nome do arquivo e diretório alterados
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
Quando eu faço a primeira conexão, até funciona, mas a partir da segunda tentativa de conexão (mesmo tendo fechado a conexão com o banco de dados) no Tracerback tem:
<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!')
Cheguei a pesquisar na internet, mas não achei nada sobre esse erro no MS Access
UPDATE
Eu fiz um teste
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)
e o resultado:
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>