SocketTimeoutException: connect timed out

That error means the query is taking longer than 1 minute to complete. Maybe there is a backup happening on the database causing it to go slow (if it is every night). It could also be a virus scanner checking that directory. You can increase the minute timeout to something higher but that will only hide the issue. I would look into a backup or virus scanner.