Prevent executing a query when no connection exists

no ref
Merge pull request #456 from halfdan/patch-1

Prevent executing a query when no connection exists