I am rebuilding a system that has developed over the past five years, initially started with Classic ASP I am now moving the whole thing to ASP.NET (using VB.NET)
The system has been plagued by a persistent problem of having too many data connections open, resulting in periodic "max_connections is exceeeded" errors.
Having asked my server hosts many times about this, I am still having troubles so thought I'd open it up to SO.
I am currently opening connections as follows:
Dim sql = "SQL SELECT"
Dim oConnection As OdbcConnection = New OdbcConnection(ConfigurationManager.ConnectionStrings("dbConn").ConnectionString)
oConnection.Open()
openDatabase = New OdbcCommand(sql, oConnection)
The connection string is contained with the web.config file and looks like this
<add name="dbConn" connectionString="DRIVER={MySQL ODBC 3.51 Driver}; SERVER=mysql.dc-servers.com; DATABASE=dbName; UID=user; PASSWORD=pwd; OPTION=3; pooled=true" providerName="System.Data.Odbc"/>
I am getting actual data using a DataReader like this:
Dim objDataReader As OdbcDataReader
objDataReader = openDatabase.ExecuteReader(CommandBehavior.CloseConnection)
While (objDataReader.Read())
// do stuff
End While
objDataReader.Close()
It is my understanding that, assuming there are no errors with the data or database (CommandBehavior.CloseConnection)
should ensure that when the line objDataReader.Close()
closes the Reader, it should close the connection too (or return it to the pool)
I'm getting these max_connections errors though.
Looking at the open processes on MySQL admin, I can see that the connections are not being closed.
I have minimal understanding of the connection process I am afraid and very limited access to the MySQL server, so struggling to find out what is going on here... unless of course... I have misunderstood something, which I hope is the case and you guys can point me to it!