0

I'm working on a project that requires me to use an SQL database, and the software I have available to use is Microsoft Access. I've looked around various forums (including this one) for help with the connection between Python and Access, but my error is never resolved. Here's my code:

import pyodbc

connect =  pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\\Users\\User\\Documents\\My Folder\\leaderboards.accdb;')
cursor = connect.cursor()
cursor.execute('select * from level1')
   
for row in cursor.fetchall():
    print (row)

And the error I keep receiving is this:

connect =  pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\\Users\\User\\Documents\\My Folder\\leaderboards.accdb;')
pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

I'm pretty new to using SQL stuff (I only know how to query the database, I've never integrated it with a separate program) so I don't know exactly where the error lies, and I'm not familiar with the format of such functions so I don't know what parts are placeholder and what are actual code.

I've tried reinstalling and updating drivers and I've made every amendment I can think of or find, but nothing changes, so there's obviously something fundamental I'm missing here.

How can this be solved?

Many thanks

cwdii
  • 1
  • 2
  • I'd advise you not to use Access as it has been deprecated, and in any case has usability issues. Try SQL Server LocalDB, and use SSMS to build the DB and write and test queries. It's from Microsoft and is free – Charlieface Jan 20 '21 at 16:32
  • 1
    @Charlieface Access has not been deprecated and is actively being developed. cwdii unfortunately, with the information you've provided, I have no additional clues, outside of the general guidance outlined in the duplicate. Check the ODBC driver panel to see if you have the driver installed, check the bitness of Python and make sure it matches the driver. – Erik A Jan 20 '21 at 17:37

0 Answers0