Test connection and query