Sqlserver
 sql >> Datenbank >  >> RDS >> Sqlserver

pyodbc.connect() funktioniert, aber nicht sqlalchemy.create_engine().connect()

Ein Pass Through Exact Pyodbc String funktioniert bei mir:

from sqlalchemy import create_engine
from sqlalchemy.engine import URL

connection_string = (
    r"Driver=ODBC Driver 17 for SQL Server;"
    r"Server=(local)\SQLEXPRESS;"
    r"Database=myDb;"
    r"Trusted_Connection=yes;"
)
connection_url = URL.create(
    "mssql+pyodbc", 
    query={"odbc_connect": connection_string}
)
engine = create_engine(connection_url)
cnxn = engine.connect()
rows = cnxn.execute("SELECT name FROM sys.tables").fetchall()
print(rows)