Fixed connection selection in count()

The proper connection was not used in the count function