Pyodbc Error: ('HY000', 'The driver Did not Supply an error!')

Asked

Viewed 369 times

0

I’m having a little trouble using the pyodbc to connect to an MS Access.

Until a few days ago, everything was operating normally, but after updating my Anaconda, a persistent error occurred in the system.

Error: ('HY000', 'The driver did not supply an error!')

In this case, it follows an excerpt from the code:

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

When I make the first connection, it even works, but from the second connection attempt (even having closed the connection with the database) in Tracerback has:

<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!')

I even searched the internet, but I found nothing about this error in MS Access

UPDATE

I took a test

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)

and the result:

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>
  • No other option than ODBC? Personally speaking, I hate ODBC... Anyway... At least this bit of code is not wrong. you are calling again Conn, cur = conn_cur_access_db(path, base)? Imo would be better to make a class for the connection so as not to keep writing the same code over and over again. If you have any problem is in the rest of btw code.

  • In fact, this function is within a class of well repeated functions, and unfortunately it is ms access even, I have no way to change the company database.

  • Then it will be necessary refactoring for object orientation, facilitating code debugging. Otherwise, you will have to look for the bug. Because some line of code is not allowing streaming of the accdb. file to end. If the driver does not post an error it is exactly because it did not succeed in streaming the file. It’s a 10min thing. to make a class with CRUD service, and it’s much more reliable than structured code

  • 1

    I forgot to tell you.. Another thing, sometimes you may have updated the pyodbc module because of the anaconda update. And some pyodbc command may have changed. If so, use a virtual environment with the correct version, or arrange the code to work in the latest version

  • In this case, the error occurs in the connection string, i.e., before opening connection to the database. Is there a problem when doing the Conn.close()? Since the problem occurs when you will open the database again.

  • Could answer some code to see as an example?

  • I’ll just have time to take a look at this weekend : trampo+facul is killing

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.