melca
melca

Reputation: 23

SQLAlchemy - 'engine' object has no attribute 'cursor'

I was working on this code for the last few months and never had issues with sqlalchemy and connection to my ms sql database. However, yesterday I installed dataset, tokenizer, sklearn and joblib, and now my database connection is not working.

This is my connection part of the code that worked without issues before:

connection_string = (
    'mssql+pyodbc:///?odbc_connect='
    f'DRIVER={{ODBC Driver 18 for SQL Server}};'
    f'SERVER={server};'
    f'DATABASE={database};'
    'Trusted_Connection=yes;'
    'TrustServerCertificate=yes;'
)

engine = create_engine(connection_string)

df = pd.read_sql('table', engine)

Now I have error message: 'Engine' object has no attribute 'cursor'

I have tried changing versions of sqlalchemy, pyodbc, but still the same error occurs. I also tried - read_sql_table, read_sql_query.

Thank you for your help!

UPDATE I managed to fix this by deleting all python libraries and installing them all over again, however I would still appreciate a solution for this problem.

Upvotes: 1

Views: 97

Answers (0)

Related Questions