Test for SQL reconnection

Testing the closing of the SQL connection at the end of the loop and
reopening it when the loop starts again.