locked
MySQL exceeded the 'max_user_connections' RRS feed

  • Question

  • User1702646864 posted

    I close my connection to the database, but after several insertions into the database, I am getting the max_user_connections error. Is there something I am doing wrong in my code?

    Imports System

    Imports System.Data

    Imports MySql.Data

    Imports MySql.Data.MySqlClient

    Imports MySql.Data.MySqlClient.MySqlCommand

    Imports MySql.Data.MySqlClient.MySqlDataReader

     

    Partial Class Add

    Inherits System.Web.UI.Page

    Dim myConn As MySqlConnection = New MySqlConnection("server=xxxx;port=3306;database=xxxx;username=xxxx;password=xxxx")



    Protected Sub btnAddScores_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttonAddScores.Click
    Dim strTeam1ID As String
    Dim strTeam2ID As String



    Try

    myConn.Open()



    Dim myCmd As New MySqlCommand
    myCmd.Connection = myConn



    'insert into table

    Dim strWeek = ddlWeeks.SelectedItem.Text
    Dim strScore1 = txtScore1.Text
    Dim strScore2 = txtScore2.Text
    Dim strTeam1ID = txtTeam1.Text
    Dim strTeam2ID = txtTeam2.Text
    Dim strSQL As String = "INSERT into nfl_scores_2010 VALUES ('" & strWeek + "','" & strTeam1ID & "','" & strTeam2ID & "','" & strScore1 & "','" & strScore2 + "')"



    myCmd.CommandText = strSQL
    myCmd.ExecuteNonQuery()

    myConn.Close()
    myConn.Dispose()


    Catch ex As MySqlException

    TextBox1.Text = ex.ToString

    End Try



    Me.TextBox1.Text = "Done"


    End Sub

    
    



     

    Monday, January 3, 2011 10:09 PM

Answers

  • User1508394307 posted

    Close the connection object inside the Finally block

    Catch ex As MySqlException
        TextBox1.Text = ex.ToString
    
    Finally
        myConn.Close()   
    
    End Try

    or

    Finally
    
          If Not myConn Is Nothing Then
             If myConn.State = ConnectionState.Open Then
                myConn.Close()
                myConn.Dispose()
             End If
          End If
          
    End Try

    For more information read here.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 4, 2011 2:13 AM

All replies

  • User1508394307 posted

    Close the connection object inside the Finally block

    Catch ex As MySqlException
        TextBox1.Text = ex.ToString
    
    Finally
        myConn.Close()   
    
    End Try

    or

    Finally
    
          If Not myConn Is Nothing Then
             If myConn.State = ConnectionState.Open Then
                myConn.Close()
                myConn.Dispose()
             End If
          End If
          
    End Try

    For more information read here.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 4, 2011 2:13 AM
  • User1702646864 posted

    Thank you.

     

    One other question, I use Firefox, why does my pasted code look like it's HTML? I used the Insert Code. 

    Tuesday, January 4, 2011 12:35 PM