Python pyodbc connect to ms access database

霸气de小男生 提交于 2019-12-22 17:06:24

问题


I am trying to connect my access database so I can dump my data into the table in the database. This the code I use:

import pyodbc
access_database_file = "C:\\Users\\Moyp\\DataPointe.accdb"
ODBC_CONN_STR = 'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=%s;' %access_database_file
conn = pyodbc.connect(ODBC_CONN_STR)

However, I keep receiving this error:

Traceback (most recent call last):
  File "C:\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3035, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-6-a4daec7c49a9>", line 1, in <module>
    conn = pyodbc.connect(ODBC_CONN_STR)
Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

回答1:


I fixed the issue. I was using 64 bit Python and 32 bit MS Access. After I downgraded my 64 bit Python to 32 it worked fine.



来源:https://stackoverflow.com/questions/31320509/python-pyodbc-connect-to-ms-access-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!