moved db selection past valid connection