Connection isn't released on MyConnection.Close
Posted by:
Karel Boek
Date: November 30, 2004 05:43AM
Environment:
- MySQL 4.1.7
- Windows 2003 Server
- IIS 6.0
- .NET Framework 1.1
- VB.NET
- MySQL Connector/Net (ADO.NET driver for MySQL) version 1.0.2
Problem:
Connection to a MySQL database is made and values are read into a DataReader, a DataGrid or a DataList. After every connection made, I close the connection and dispose it. However, after a while the error message "too many connections" appears. Using MySQL administrator, I find my web application having 100 (the default) connections to the server.
Question:
What is happening here? It seems like my code doesn't really close the connection to the MySQL server. Is that a bug or is it my code (most likely)?
Code:
Dim QueryString As String = "SELECT * FROM mytable"
Dim dbConnectionString As String = "Database=db;Data Source=localhost;User Id=*;Password=*"
Dim dbConnection As New MySqlConnection(dbConnectionString)
Dim dbCommand As New MySqlCommand(QueryString, dbConnection)
Dim dbDataReader As MySqlDataReader
dbConnection.Open()
dbDataReader = dbCommand.ExecuteReader(CommandBehavior.SingleRow)
While dbDataReader.Read
Return dbDataReader.Item(Setting)
End While
dbDataReader.Close()
dbConnection.Close()
dbConnection.Dispose()
dbConnection = Nothing
Does That Make Sense?
Subject
Written By
Posted
Connection isn't released on MyConnection.Close
November 30, 2004 05:43AM
November 30, 2004 09:10AM
December 01, 2004 06:26AM
December 21, 2004 11:32AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.