2

I am trying to connect to an MS Access (2013, 64 bits) database I created. However I am getting the following error:

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

I know the question has been asked before and the solution usually seems to have to do with string formatting, but I could not make my script work.

Here is my code:

import pyodbc

con_string = 'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Temp\Database1.accdb;'
con_string2 = 'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};UID=admin;UserCommitSync=Yes;Threads=3;SafeTransactions=0;PageTimeout=5;MaxScanRows=8;MaxBufferSize=2048;FIL={MS Access};DriverId=25;DefaultDir=C:/temp;DBQ=C:/temp/Database1.accdb;'

try:
    mdb_con = pyodbc.connect(con_string2)
except pyodbc.Error as error:
    print error, "Can't connect"

Note that I created two connection strings, the first one based on what I saw online, and the second one using a DSN file I created using the Access database.

Naci
  • 231
  • 3
  • 16
  • 1
    Add `import struct` to the top of your script and then have it `print("running as {0}-bit".format(struct.calcsize("P") * 8))`. What does it tell you? – Gord Thompson Sep 16 '16 at 18:28
  • 1
    As @GordThompson advises, check if your Python installaiton is 32-bit/64-bit as it would affect interfacing to a 64-bit Access database. – Parfait Sep 16 '16 at 18:56
  • Yes, it says running as 32-bit. Do I need 64-bit python? – Naci Sep 16 '16 at 20:33
  • 2
    Installing 64 bit Python and pyodbc solved the issue. Thanks!! – Naci Sep 16 '16 at 21:04

0 Answers0