Support external database connections

This PR adds support for external database connections.