sql >> Database teknologi >  >> RDS >> Sqlserver

pyodbc.connect() virker, men ikke sqlalchemy.create_engine().connect()

En Pass through nøjagtig Pyodbc-streng virker for mig:

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)



  1. SQL-transponer fuld tabel

  2. Introduktion til diagramtyper

  3. Forskellen mellem N'String' vs U'String' bogstaver i Oracle

  4. Er mysql_real_escape_string() brudt?