How do I connect to SQL Server via sqlalchemy using Windows Authentication?

后端 未结 4 673
半阙折子戏
半阙折子戏 2020-12-05 03:57

sqlalchemy, a db connection module for Python, uses SQL Authentication (database-defined user accounts) by default. If you want to use your Windows (domain or local) credent

4条回答
  •  暖寄归人
    2020-12-05 04:42

    pyodbc

    I think that you need to put:

    "+pyodbc" after mssql

    try this:

    from sqlalchemy import create_engine
    
    engine = create_engine("mssql+pyodbc://user:password@host:port/databasename?driver=ODBC+Driver+17+for+SQL+Server")
    
    cnxn = engine.connect()
    

    It works for me

    Luck!

提交回复
热议问题