Ah; if you already use a connection pool then you may already be okay
as the driver will just pool the connection instead of really
'closing' it, so performance loss would be minor compared to using an
unpooled connection.
Two points though for you:
1) Are you sure you are hitting a limit on connections? 'Connection
refused' I am sure is the server explicitly saying to your client "I
dont have that port open for you to connect on". I would expect an
error like "Connection failed to respond in a suitable time" or
another timeout related message when trying to connect, if you were at
a connection limit on the server, instead of a flat out refusal. I
could be wrong though. Perhaps you should check whether a firewall or
something is kicking in and blocking your connections?
2) If you do have excessive amount of connections though, this could
be attributed to you not really closing the connection when you were
finished with it inside your application code, although disposing of
the connection should do it.
You could try reloading the same page over and over and seeing whether
your connections count on mongo (if you can check some how) keeps
increasing?
- Andrew