Can't connect to Microsoft Access in 5.1.0
Closed this issue · 4 comments
Environment
To diagnose, we usually need to know the following, including version numbers. On Windows, be
sure to specify 32-bit Python or 64-bit:
- Python: 3.11
- pyodbc: 5.1.0
- OS: Windows 64
- DB: Microsoft Access
- driver: Microsoft Access Driver (*.mdb, *.accdb)
Issue
Can't connect to Microsoft Access in 5.1.0, but it's ok in 4
I am unable to reproduce your issue. Please provide more info (repro code, error message).
Code
import pyodbc, os
dbfile = r'C:\Users\ryjfgjl\Desktop\Database2.accdb'
if os.path.exists(dbfile):
conn_str = (
rf'DRIVER=Microsoft Access Driver (*.mdb, *.accdb);'
rf'DBQ={dbfile};'
)
db_connection = pyodbc.connect(conn_str, autocommit=False, encoding='utf8')
Error:
Traceback (most recent call last):
File "D:\Projects\DiLu Converter\DiLu Converter\test.py", line 9, in
db_connection = pyodbc.connect(conn_str, encoding='utf8')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序 (0) (SQLDriverConnect); [IM002] [Microsoft][ODBC 驱动程序管理器] 无效的连接字符串属性 (0)')
PS: It OK when I remove autocommit=False
I'm sorrty ,it looks like the option "encoding='utf8'"
Remove , encoding='utf8'
from the .connect()
call.