[Python] Connection to SQL Server using Microsoft Entry MFA via sqlalchemy and ODBC in python...

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

  1. Stack

    Stack Membro Participativo

    I am writing a python script that connects to Azure Serverless SQL and exports the rows for a given query. I am using sqlalchemy. I build the connection string

    connection_string = 'DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';Authentication=ActiveDirectoryInteractive;Encrypt=yes;TrustServerCertificate=no;UID='+username


    and it prompts for a password as expected

    When I change it to this

    connection_string = 'DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';Encrypt=yes;TrustServerCertificate=yes;UID='+username+';PWD ='+password+';Authentication=ActiveDirectoryPassword'


    It throws this message


    [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
    ​

    How can I get it not to prompt for a password on the connection since I prompt for it before hand. Since I am running several python scripts that do this, I only want to have to enter my password once.

    Continue reading...

Compartilhe esta Página