Prevent executing a query when no connection exists

no ref