2

So I want to make my program to not connect to a microsoft database and if the connection takes longer then 3 seconds then to show an error then quit the program, also all using pyodbc.

def SpecialFunc(server:str,port:str,username:str,password:str,db_name:str):
    try:
        pyodbc.SQL_CONVERT_TIME = 1
        conn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER={'+server+'};PORT={'+port+'};DATABASE={'+db_name+'};UID={'+username+'};PWD={'+password+'};')
    except Exception as e:
        print(e) 

This CODE DOESN'T WORK and I can't figure out so may someone help me?

1
  • Hi @DanielZheleznov, could you be more specific, what does not work ? I assume the connection to the database works fine ? But you are unable to get the timeout error and display it ? Anyhow, please give us as much details as possible instead of this code does not work. Cheers
    – Paulo
    Commented Sep 18, 2021 at 17:50

0

Browse other questions tagged or ask your own question.