0

I am doing a school project in which i need to connect to a database. I have no experience of doing this however after reseaching online i found using pyodbc would work. I am using a microsoft access for my database as it is the only software my school has. I installed the odbc driver and the pyodbc package but when I attempt to connect, I receive an error message

I tried using the following code to connect.

conn = pyodbc.connect('Driver={Microsoft Access Driver};Server=my servername;Database=mydbname;Trusted_Connection=yes;')

However i get the following error message

InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

I am not 100% sure i have used the right details in my connection string as I couldn't find a solid answer on where i would find my server name. I also tried using the following connection string.

conn = pyodbc.connect(
    r"Driver={Microsoft Access Driver(*.mdb, *.accdb)};"
    r"DBQ=C:\my_db_path.aacdb;"
    r"PWD=mypassword;"

However I get the following error message

InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

Could anyone help me fix this issue as i have checked countless websites for help but nothing seems to work. Thanks

franklyn05
  • 11
  • 2
  • I presume you used your actual server name and password in place of the generic examples. The db is password encrypted? Why are use Python - is this a class assignment? – June7 Mar 25 '23 at 07:04
  • @June7 Yes I have used my computers hostname for server name and the password for the database. I am using python as it is what my high school teaches and asks us to use – franklyn05 Mar 25 '23 at 09:38
  • Your second attempt is almost correct, you are just missing a space. The driver name is `Microsoft Access Driver (*.mdb, *.accdb)` – Gord Thompson Mar 25 '23 at 10:39
  • @GordThompson Thanks. I tried running with the space however im still getting the error message above – franklyn05 Mar 25 '23 at 11:22
  • I have now got the connection running, I had to install the 64 bit MS Access Driver as I had the 32 bit one. Thanks for all the help and I may post more questions as I really am clueless with all of this. – franklyn05 Mar 25 '23 at 12:22
  • Does this answer your question? [Connect to MS Access in Python](https://stackoverflow.com/questions/50757873/connect-to-ms-access-in-python) – June7 Mar 25 '23 at 21:14

0 Answers0