R'DBQ=E:\PythonInOffice\python_connect_to_ms_access\database.accdb ')Ĭonn = nnect(conn_str) Find all tables and queries in the MS Access database For MS Access, we also need to specify the type of ODBC driver (32bit vs 64bit) in the connection string.Īlso make sure you close the MS Access database before making the connection, otherwise there will be an error. To connect to a database, we need a connection string, basically a text pointer that tells Python where to find the database. The above result shows that my computer has the new 64-bit Access (and driver). This list comprehension iterates through all available ODBC drivers and only returns the ones that start with “Microsoft Access Driver”. To check which version of the Access ODBC driver is on your computer, do the following in Python: >import pyodbc In case you don’t have the driver, you can download a standalone version on Microsoft’s website: Your machine should already have one of the drivers if you have MS Office installed. New Driver (64-bit) – Microsoft Access Driver ( *.mdb, *.accdb): works with 64-bit Python.Old Driver (32-bit) – Microsoft Access Driver ( *.mdb): works with 32-bit Python. The reason is that there are two different Access ODBC drivers from Microsoft: Mixing up a 64-bit Python with 32-bit Access will throw an error when you try to connect. One thing to note upfront, if you have 64-bit MS Access, you’ll want to use the 64-bit Python for this exercise. TL DR – You need 32-bit Python for 32-bit Access, or 64-bit Python for 64-bit Access. Install pyodbc and check ODBC driver version pip install pyodbc
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |