Refactor connection handling

Work in progress, just getting my travis on.

This PR should solve issues with transactions setting up too many connections, transaction not closing their connections and other stuff.

This PR should also help make the connnection codebase more understandable and more general per dialect.
Pffft.