我有幾十個人使用的pc程序,並且隨着人們連接到數據庫的增加,程序開始拋出大量數據庫連接的錯誤。我檢查數據庫後,每個查詢創建一個進程是在數據庫中的「睡眠」,如果你超過了數字50是上述錯誤崩潰。如果問題出在程序或託管上,我該如何補救?vb net max_user_connections到mysql
數據庫屏幕;
http://obrazki.elektroda.pl/5375287900_1423553806.png
代碼:
Public Sub loginUser(ByVal sql As String)
Try
Dim maxrow As Integer
con.Open()
dt = New DataTable
With cmd
.Connection = con
.CommandText = sql
End With
da.SelectCommand = cmd
da.Fill(dt)
maxrow = dt.Rows.Count
If maxrow > 0 Then
Form1.Show()
Else
Label3.Text = ("Invalid Username or Password!")
Label3.Visible = True
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
con.Close()
da.Dispose()
End Sub
Private Sub InsertData()
sql = "SELECT * from users WHERE login = '" & (username.Text) & "' and pass = '" & StringtoMD5(password.Text) & "'and banned = '" & 0 & "'"
loginUser(sql)
End Sub
使用全局變量保持連接對象是問題的主要罪魁禍首。不要這樣做。使用本地連接對象,打開它並在完成後處置。 – Steve 2015-02-10 08:42:27
我不知道該怎麼做,如果我可以要求這樣一個連接的例子嗎? – 2015-02-10 09:06:47