As I am new to Vb, I am not sure if this is even possible.

i have created a program and now we are testing the maximum clients possible for the server.the thing is since, we are at the beggining stage, we come across numerous errors and so the person remains logged in without logging out.after a while it becomes a hassle to keep removing logged in members from the database so that they can login again.

so my question is, on any error if the program crashes, is there a way to run two lines of code

strnew2 = New SqlCommand("DELETE FROM loggedin WHERE usernam = '" & Me.LinkLabel1.Text & "' ", thisConnection)
                strnew2.ExecuteNonQuery()

this way i can run it more smoothly.
Thanks.

I think you can Use Try-Catch

Try
thisConnection.Open()
strnew2 = New SqlCommand("DELETE FROM loggedin WHERE usernam = '" & Me.LinkLabel1.Text & "' ", thisConnection)
                strnew2.ExecuteNonQuery()
Catch(e As Exception)
'If error or crash occure catch will get executed .
MsgBox("Error "+e.Message)
Finally
'Error occur or not Finally execute both time. So thisConnection.Close() is guaranteed
thisConnection.Close()
End Try

Edited 4 Years Ago by kingsonprisonic: n/a

Comments
quick to reply
This question has already been answered. Start a new discussion instead.