Ensure SQL connection before database selection