1

Need help using a trusted connection to connect to SQL Server using SQLALCHEMY

So far I have this code to establish the connection

import sqlalchemy as sa
engine = sa.create_engine("mssql+pyodbc://REPORTING/REPORTING_System?driver={SQL Server}?TrustedConnection=yes")
view = f"SELECT Date From Table"
df = pd.read_sql_query(view, engine)

However I got this error message - DBAPIError: (pyodbc.Error) ('01S00', '[01S00] [Microsoft][ODBC Driver Manager] Invalid connection string attribute (0) (SQLDriverConnect)') (Background on this error at: https://sqlalche.me/e/14/dbapi)

I tried to change the driver to {ODBC Driver 17 for SQL Server} It did not help.

dli193
  • 11
  • 2
  • I hope this will help you : https://stackoverflow.com/questions/46045834/pyodbc-data-source-name-not-found-and-no-default-driver-specified/46055035#46055035 – Omar Tougui Feb 02 '23 at 17:15
  • Have you read through [Pass through exact Pyodbc string](https://docs.sqlalchemy.org/en/20/dialects/mssql.html#pass-through-exact-pyodbc-string) yet? Except use `{ODBC Driver 17 for SQL Server}` or whichever version you have installed. – AlwaysLearning Feb 04 '23 at 08:18
  • As to `TrustedConnection=yes` that would normally be `Trusted_Connection=yes` with an underscore, but it's normally only applicable in Windows environments where you're trying to connect to an SQL Server using the Windows/Active Directory authentication attached to the current process, or in rare cases Linux-based processes where you have a valid Kerberos authentication token. Ref: [Using Integrated Authentication](https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/using-integrated-authentication). – AlwaysLearning Feb 04 '23 at 08:19

0 Answers0