[Python] How can I connect Python to MS SQL Server with a different Windows user? [duplicate]

Discussão em 'Python' iniciado por Stack, Maio 24, 2025.

  1. Stack

    Stack Membro Participativo

    I enter a new Windows username and password with "run as a different user" to connect to SSMS. I need to import the data there into Python.

    However I get an error:


    InterfaceError: ('28000', "[28000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'domain\username'. (18456) (SQLDriverConnect); [28000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'domain\username'. (18456)")
    ​

    I am trying the following code:

    import pyodbc

    conn = pyodbc.connect('Driver={SQL Server Native Client 11.0};'
    'Server=Server;'
    'Database=Database;'
    'UID=domain\username;'
    'PWD=password;')

    Continue reading...

Compartilhe esta Página