Usually in batch type of MySql client code you might have seen this exception before:
MySqlException: Unable to connect to any of the specified MySQL hosts
(or similar, this one is specific to MySql .Net client)
Of
course it might be what it says, but actually message can be a little
misleading if it happens in some batch jobs (with huge number of
connects and disconnects) but nowhere else.
After a little
digging and debugging in the MySql .Net client library code it became
obvious that it was a low level TCP socket issue. Because of the high
number of connects and disconnects, OS (WinXP/2003 in this case) network
layer was not finding enough user ports to assign to the server (by
design TCP keeps the connection in a TIME_WAIT state before disposing
the connection). Little googling quickly relieved a few solutions:
First
one is simple. If you can alter the code, the obvious solution is to
use pooling or keep the connection around while querying the database.
This would be much more efficient as well.
Refer this for more details
http://ziya.suzen.net/2009/01/mysql-high-volume-connection-issue-when.html