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

后端 未结 4 672
半阙折子戏
半阙折子戏 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:29

    If you're using a trusted connection/AD and not using username/password, or otherwise see the following:

    SAWarning: No driver name specified; this is expected by PyODBC when using >DSN-less connections "No driver name specified; "

    Then this method should work:

    from sqlalchemy import create_engine
    
    server = 
    
    database = 
    
    engine = create_engine('mssql+pyodbc://' + server + '/' + database + '?trusted_connection=yes&driver=ODBC+Driver+13+for+SQL+Server')
    

提交回复
热议问题