I’m using Asp.Net together with MySql and I’m trying to solve the error:
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.
I’m trying to make sure that I’m not leaking any connections.
I need to know the status of the connection pool (how many connections are open right now)? In this thread I learned that I can use the Performance Monitor to know the pool count. But how can I do that when using MySql instead of Sql Server?
Original Reference for the above code discussed below is here:
I’ve done the following with Oracle, I think it can work with MySQL with some small modifications (e.g. change
OracleConnection, etc.). You can create a class called ConnectionSpy (see below). This is in VB.Net, you could convert the code to C# if you choose.Then, in your web.config/app.config, you can add a section like this:
Then, wherever in your code you create a DB connection, you can do this (see below).The
mConnectionvariable would represent your MySQL connection, which you would have already created when you get to this point.So then, if you have any connections that are being garbage collected before they’re closed, it will be reported in the log file. I’ve used this technique in some of my applications and it works well.
What you would need to do is create a wrapper class for your MySQL DB Connections, and you can put the above code in place to track the connections. Or, you could just add the above calls to wherever you create your connections. The wrapper class is a bit cleaner though (that’s what we did)