Hi vasto_form96 welcome to the forum
I'd have to google to know what "2002" indicates, but the "connection timed out" seems perfectly clear.
AFAIK you have two choices, either adjust your database settings to allow longer connection time, or make whatever query is taking too long more efficient.
IMHO, fixing the query would be the best approach. Please post the table schema and the problem query.