I have very large dataframe I'd like to directly write into a MS Access Database.
My current approach looks like this
import pandas as pd
from sqlalchemy import create_engine
from sqlalchemy.engine import URL
accdb_path = r"C:\Users\Public\test\TEST.accdb"
connection_string = (
"DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};"
f"DBQ={accdb_path};"
"ExtendedAnsiSQL=1;"
)
connection_url = URL.create(
"access+pyodbc",
query={"odbc_connect": connection_string}
)
engine = create_engine(connection_url)
df = pd.DataFrame([(1, "foo"), (2, "bar")], columns=["id", "txt"])
df.to_sql("my_table", engine, index=False, if_exists="append")
(... ) which yields
InterfaceError: (pyodbc.InterfaceError) ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] The data source name was not found and no default driver was specified (0) (SQLDriverConnect)') (Background on this error at: https://sqlalche.me/e/14/rvf5)
Although the specified driver is installed and the path to the database surely is correct!