views:

98

answers:

1

In the application that I am making right now, I am getting this error:

error connecting: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.

Evidently I am touching max-count in the connection pool. I am dutifully using 'using' with all connection objects and freeing them up immediately when the function is done with them.

This is on C#, and I am using the MySql Data Dll.

Is there something wrong with the dotnet connector for MySql? Is there a workaround?

+1  A: 

A few things to check first:

  • Have you verified that your application isn't trying to use more connections concurrently than the number allowed by the connection pool? This could easily happen if the operations you're doing while using a connection are quite long lived (something to avoid anyway).

  • Are you passing around a DataReader, rather than disposing it properly when you're done with it. That could be holding on to the connection.

As a stopgap, you could try setting 'pooling=false' in the connection string, although that will cost performance.

For more information on use of connection pooling, see Using Connector/NET with Connection Pooling

FrederikB
No I am not passing a Datareader around, and I am indeed disposing it using 'using'. I am passing a Command object around though. There are no long operations, but a number of short ones and I dispose the object each time. Hard to imagine that could cause an overflow in the connection pools.
Cyril Gupta
Can you isolate the problematic behaviour to simple code sample and post it here?What version of the .net connector are you running?
FrederikB
I don't think this is due to any specific piece of code, but could be due to the overall way I work with the DLL. I haven't faced this problem in an earlier app that is not any less db intensive and is based on the same structure. Version of the MySQL dll is 5.0.9.0
Cyril Gupta
Just reread your earlier comment - you're passing around command objects - mySqlCommand objects have a connection property. Is it possible you're leaking via the command objects?
FrederikB
It could just be possible Frederik. I've posted a relevant question.
Cyril Gupta