Click here to Skip to main content
15,845,367 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I try to connect a password protected access 2007 database file, password is 'AaBbCc'. I am getting an error -
ERROR
Traceback (most recent call last):
  File "E:\MasterMindAcc\Pyh\Login.py", line 45, in <module>
    conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.accdb)};DBQ=H:\\MasterMindAcc\\Sys\\NetNo.accdb;password=AaBbCc')
pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')


What I have tried:

making a login form for my accounting app use login
read access 2007 .accdb database for checking user id and password
Posted
Updated 30-Nov-23 8:17am
v2

1 solution

Your error suggests that your Data Source Name (DSN) is not found, and there is no default driver specified by you on where to find it.

When using Python, the 'pyodbc' library is needed to connect to the Access database. Make sure that you have the 'pyodbc' library installed using your console, More on this as a tutorial at pyodbc | Tutorial[^] -
Bash
pip install pyodbc


Your code should then look something like the following to connect -
Python
import pyodbc

db_path = r'H:\MasterMindAcc\Sys\NetNo.accdb'
password = 'AaBbCc'

#Your connection string here...
conn_str = f'DRIVER={{Microsoft Access Driver (*.mdb, *.accdb)}};DBQ={db_path};PWD={password}'

try:
    #Make the connection...
    conn = pyodbc.connect(conn_str)

    #Add your code for all your database operations here...

    #Close the connection when done...
    conn.close()

except Exception as e:
    print(f"Error: {e}")
 
Share this answer
 
v3
Comments
Maciej Los 30-Nov-23 15:57pm    
5ed!
Andre Oosthuizen 1-Dec-23 11:13am    
Thanks Maciej!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900