我的VB.NET应用程序开始出现错误:
Timeout Expired. The timeout 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.
我确实有一些无法正确处理连接的方法.这些已使用“尝试并最终”修复.
但是,今天早上,我在尝试打开简单报告时再次收到错误消息.我打开了MySQL Workbench,以监视客户端连接.当时我连接了4个线程.
MySQL数据库将杀死已休眠超过15秒的连接.
我确实不知道如何达到最大池大小,如果确实是错误所指的话.
应用程序是否读取最大池大小设置并保存自己的连接数并在达到该数目时抛出错误,还是每次打开新连接时直接从MySQL DB获取该数目?
还是该错误可能是由于其他原因引起的?
编辑1
MySQL Workbench的一些统计信息
连接的线程数:3
正在运行的线程数:1
创建线程:250
缓存的线程数:5
拒绝(超出限制):0
总连接数:2822
连接限制:151
中止的客户:2694
中止连接:84
错误:0
编辑2
调用和处置连接的示例代码:
Public Shared Function GetCoursePaperCertificate(ByVal CourseTypeID As Integer) As String
Dim connx As New MySqlConnection(My.Settings.BMConnString)
Try
Dim cmdTextx = "Select `Cert` From `Courses` WHERE `ID`=@ID"
Dim cmdx As New MySqlCommand(cmdTextx, connx)
cmdx.Parameters.AddWithValue("@ID", CourseTypeID)
connx.Open()
Dim result = cmdx.ExecuteScalar
If result Is Nothing OrElse result Is DBNull.Value Then
Return String.Empty
Else
Return result
End If
Catch ex As Exception
Return String.Empty
Finally
connx.Dispose()
connx = Nothing
End Try
End Function