[Python] Connect to my SQL database on Python but I can connect with same login credentials on...

Discussão em 'Python' iniciado por Stack, Abril 8, 2025.

  1. Stack

    Stack Membro Participativo

    I've been trying to connect to an SQL database for work. I have the login credentials and everything but when I try to connect I get this error:


    OperationalError: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. (17) (SQLDriverConnect); [08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). (53); [08001] [Microsoft][ODBC Driver Manager] Invalid connection string attribute (0)')
    ​

    However when I go through the same process using Microsoft SSMS, I am able to login with no issues. I noticed that I had to click trust certificate and keep encrypt on mandatory so that I don't get an error with SSMS and so I tried the same for my python code but got the same result.

    my code is as follows:

    connection_string = f"""
    DRIVER={{SQL Server};
    SERVER={server};
    DATABASE={database};
    UID={user};
    PWD={password};
    Encrypt=yes;
    TrustServerCertificate=yes; #I've switched between 'true' and 'yes'
    """


    Help would be very much appreciated.

    Continue reading...

Compartilhe esta Página