Smith Smith - 9 months ago 66
Python Question

Python importing from MS Access: "Invalid connection string attribute"

I am trying to import data from a MS Access database

import pyodbc

connStr = """

import pypyodbc
Driver={Microsoft Access Driver (*.mdb, *.accdb)}
DBQ = C:\\Users\\haesh\\Desktop\\Comp Sci CC\\Database1.accdb;

cnxn = pyodbc.connect(connStr)

However I get this error

Traceback (most recent call last):
File "C:\Users\haesh\Desktop\Comp Sci CC\", line 10, in <module>
cnxn = pyodbc.connect(connStr)
pyodbc.Error: ('01S00', '[01S00] [Microsoft][ODBC Driver Manager] Invalid connection string attribute (0) (SQLDriverConnect)')


The import pypyodbc does not belong in the ODBC connection string. Also, connection strings can be confused by line breaks and white space. You should have better luck with this:

connStr = (
    r"Driver={Microsoft Access Driver (*.mdb, *.accdb)};"
    r"DBQ=C:\Users\haesh\Desktop\Comp Sci CC\Database1.accdb;"