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
commented: quick to reply +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.