Skip to content
Advertisement

How to retry after sql connection failed in python?

Whats the right way to retry when connection/write to a DB fails in python?

Im trying to use this code and it works until i restart my sql server and python tries to connect to it i get “retry after 30 sec” for 10 times with 30 secs intervalls but it wont reconnect when sql server is running agian.

EDIT: It reconnects when retry_count1 = 10 but at next cycle counter needs to count up to 10 before it connects agian.

Does anyone have a idea why it wont reconnect?

Heres console output after restarting sql server.

Advertisement

Answer

I found a solution by adding cnxn.close and create a new connection.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement