[Python] Is there a way to check if sqlite3.connect() succeeded or not in connecting to an SQL...

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

  1. Stack

    Stack Membro Participativo

    I'm trying to find a way to check if there was a successful connection to a database in sqlite3 and Python. I'm doing this because I'm making a password manager and want to make sure that I'm actually connected to the database and there's no errors in doing so. I started Python and SQL today, and only really have experience in C, so I'm still working through some growing pains.

    I've tried these solutions:

    1)

    if sqlite3.connect == sqlite3.Connection :
    print("CONNECTED TO PASSWORD DATABASE.")
    running = True
    else :
    print("ERROR CONNTECTING TO DATABASE. RESTART PROGRAM.")
    running = False


    if sqlite3.Error :
    print("ERROR CONNTECTING TO DATABASE. RESTART PROGRAM.")
    running = False
    else :
    print("CONNECTED TO PASSWORD DATABASE.")
    running = True


    if sqlite3 == 0 :
    print("ERROR CONNTECTING TO DATABASE. RESTART PROGRAM.")
    running = False
    else :
    print("CONNECTED TO PASSWORD DATABASE.")
    running = True

    Continue reading...

Compartilhe esta Página