Connect only before the first query.

Connection to the database is only established before the first query.