Fixed handling of database connections.