You shouldn't need to close the connection, GRANT and then re-open the connection. At worst, a sleep() should suffice.