closing query results properly

all kinds of query result should be properly closed before closing the connection itself