I'm trying to connect to an Access database using ODBC and if I ask for a list of DNS providers the access driver is listed, but it won't accept it being used in the query.
I've checked and I have 32bit drivers, Access and Python (and querying the available drivers shows that we can see the drivers), so I've probably done something really stupid, so any help would be appreciated.
import pypyodbc
sources = pypyodbc.dataSources()
dsns = sources.keys()
sl = []
for dsn in dsns:
sl.append('%s [%s]' % (dsn, sources[dsn]))
print('\n'.join(sl))
b'MS Access Database' [b'Microsoft Access Driver (*.mdb, *.accdb)']
b'Excel Files' [b'Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)']
b'dBASE Files' [b'Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)']
constr = r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=D:\Database1.accdb;'
conn = pypyodbc.connect(constr, autocommit=True)
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
conn = pypyodbc.connect(constr, autocommit=True)
File "C:\Users\Paul\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pypyodbc.py", line 2434, in __init__
self.connect(connectString, autocommit, ansi, timeout, unicode_results, readonly)
File "C:\Users\Paul\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pypyodbc.py", line 2483, in connect
check_success(self, ret)
File "C:\Users\Paul\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pypyodbc.py", line 988, in check_success
ctrl_err(SQL_HANDLE_DBC, ODBC_obj.dbc_h, ret, ODBC_obj.ansi)
File "C:\Users\Paul\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pypyodbc.py", line 964, in ctrl_err
raise Error(state,err_text)
pypyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified')