Fixed database connection for custom databases

This fixes some issues occurring with multiple connections
conflicting on custom database connections such as in test.py