i’ve a huge problem.
Take a look to this sample code
private sub FUNCTION1()
dim conn as new mysqlconnection(myconnstring)
conn.open
---- do something
FUNCTION2()
----
conn.close
end sub
private sub FUNCTION2()
dim conn as new mysqlconnection(myconnstring)
....
conn.open
-- do something
conn.close
end sub
Despite i close regulary all my connection, they remains “open” on the mysql server.
I know this because i’m using MySQL Administration tool to check how many connection i open “line by line” of my source code.
In fact i get a lot of time “user has exceeded the ‘max_user_connections’ resource (current value: 5)”
My hoster permit ONLY 5 connection, but i think that if i write GOOD source code, this cannot be a problem.
So my question is: why that “damn” connections remain open ??
Thank you in advance!
Consider wrapping your MySqlConnection operations in a
Usingstatement…Any object that you instantiate within that
Using ... newstatement will be disposed of properly by the compiler. Once thatEnd Usingstatement appears, the object goes out of scop. Any objects that are declared with in theUsingblock will need to be disposed of by the developer, as per normal.In this case, you don’t HAVE to encase your Command and Reader in their own
Using, but it allows you to take advantage of the fact that they all implementIDisposable.