I have this bizarre mistake which I can't find a solution yet. I have a function which I envoke every time when I have to insert data in database. And its actually working because when i check the database entries they are actually there.
However I have this annoying mistake "There is already an open data reader assosiated with connection which must be closed". and I can't find a way to get read of it.
This is the function:
Sub InputDataValues(ByVal StrQwery As String)
Try
myconn.Open()
Dim stquery As String = StrQwery
Dim smd As MySqlCommand
smd = New MySqlCommand(stquery, myconn)
smd.ExecuteReader()
smd.ExecuteReader().Close()//I added this when I wanted to get rid if the mistake
myconn.Close()
Catch ex As Exception
Dim ErrorMessage As String = "alert('" & ex.Message.ToString() & "');"
Page.ClientScript.RegisterStartupScript(Me.GetType(), "ErrorAlert", ErrorMessage, True)
myconn.Close()
End Try
myconn.Close()
End Sub
And this is how I call it several times down in the code:
InputDataValues(StrQwery)
If anyone cam give me a hint I will be most grateful.
This is how it look when i changed it to ExecuteNonQuery
Sub InputDataValues(ByVal StrQwery As String)
Try
myconn.Open()
Dim stquery As String = StrQwery
Dim retValue As Integer
Dim smd As MySqlCommand
smd = New MySqlCommand(stquery, myconn)
retValue = smd.EndExecuteNonQuery()
myconn.Close()
Catch ex As Exception
Dim ErrorMessage As String = "alert('" & ex.Message.ToString() & "');"
Page.ClientScript.RegisterStartupScript(Me.GetType(), "ErrorAlert", ErrorMessage, True)
myconn.Close()
End Try
myconn.Close()
End Sub