checking the length of query list, convert query to string. drop the connection when error