Hi,
I'm using Visual Studio 2010 and .Net Connector version 6.3.5 and have created a web application that reads and updates a MySQL database. I'm obviously not doing something quite right as every few days the database locks up with a "too many connections" error message.
I suspect that the following peice of code is causing the problem (as it is run the most):-
Dim SqlText As String = "SELECT max(DateDisplayed) as DateDisplayed FROM UserLogs where EmployeeNumber = " & EmployeeNumber
MyConnection = ConnectToDatabase(ReadConfig("PMConnectionString"))
If MyConnection.State = 1 Then
MyCommand.Connection = MyConnection
MyCommand.CommandText = SqlText
MyDataReader = MyCommand.ExecuteReader
While MyDataReader.Read
If Not IsDBNull(MyDataReader("DateDisplayed")) Then
GetDaysSinceLastDisplay = DateDiff(DateInterval.Day, MyDataReader("DateDisplayed"), Now())
End If
End While
MyDataReader.Close()
MyConnection.Close()
MyConnection.Dispose()
MyCommand.Dispose()
End If
End If
Can anyone shed any light on what I need to do so that the database connections are properly closed so I don't get the error?
Thanks
Anita
I'm using Visual Studio 2010 and .Net Connector version 6.3.5 and have created a web application that reads and updates a MySQL database. I'm obviously not doing something quite right as every few days the database locks up with a "too many connections" error message.
I suspect that the following peice of code is causing the problem (as it is run the most):-
Dim SqlText As String = "SELECT max(DateDisplayed) as DateDisplayed FROM UserLogs where EmployeeNumber = " & EmployeeNumber
MyConnection = ConnectToDatabase(ReadConfig("PMConnectionString"))
If MyConnection.State = 1 Then
MyCommand.Connection = MyConnection
MyCommand.CommandText = SqlText
MyDataReader = MyCommand.ExecuteReader
While MyDataReader.Read
If Not IsDBNull(MyDataReader("DateDisplayed")) Then
GetDaysSinceLastDisplay = DateDiff(DateInterval.Day, MyDataReader("DateDisplayed"), Now())
End If
End While
MyDataReader.Close()
MyConnection.Close()
MyConnection.Dispose()
MyCommand.Dispose()
End If
End If
Can anyone shed any light on what I need to do so that the database connections are properly closed so I don't get the error?
Thanks
Anita