yan_collector: disconnect from db only if already connected