Smith
Smith

Reputation: 711

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\qwerty.py", line 10, in <module>
cnxn = pyodbc.connect(connStr)
pyodbc.Error: ('01S00', '[01S00] [Microsoft][ODBC Driver Manager] Invalid connection string attribute (0) (SQLDriverConnect)')

Upvotes: 1

Views: 1730

Answers (1)

Gord Thompson
Gord Thompson

Reputation: 123779

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;"
    )

Upvotes: 1

Related Questions