Nianios
Nianios

Reputation: 1426

Password expired

I have a project in vb.net and Oracle database. When the user password expired in oracle is causing an oracle exeption. I handle that exception (open a ChangePassword Form and I change the password) but I am loosing the procedure that i was ready to execute when the error appeared :
Example:

  Try
            conn = New OracleConnection
            conn.ConnectionString = gApp.ConnectString
            conn.Open()

          'Let's say that error appears here, I want to retun here after password has been changed

            cmd.Connection = conn
            cmd.CommandText = "Delete_Transaction"
            cmd.CommandType = CommandType.StoredProcedure
            OracleCommandBuilder.DeriveParameters(cmd)
            cmd.Parameters("in_transaction_id").Value = TransactionId
            cmd.ExecuteNonQuery()
            conn.Close()


        Catch ex As OracleException
           'PseudoCode:  if error is PasswordExpired->open the ChengePassForm...blah,blah
           'is handled by a Error class that i have
        Finally
            If Not conn Is Nothing Then
                conn.Dispose()
            End If
        End Try

The main problem is that the problem can be appeared everywhere in the code, I mean different procedures, different forms etc.
So I need a generic solution. Actually I cannot even imagine a right logic to approach this?. Could anyone show me a direction?

Upvotes: 3

Views: 507

Answers (2)

user2095821
user2095821

Reputation:

Use nested try catch statements:

Try
    Try
        conn = New OracleConnection
        conn.ConnectionString = gApp.ConnectString
        conn.Open()

        'Let's say that error appears here, I want to retun here after password has been changed
    Catch ex1 As OracleException
       'PseudoCode:  if error is PasswordExpired->open the ChengePassForm...blah,blah
       'is handled by a Error class that i have
    Catch ex2 As Exception
        ' throw ex2 to be handled by the parent try catch
    End Try

    cmd.Connection = conn
    cmd.CommandText = "Delete_Transaction"
    cmd.CommandType = CommandType.StoredProcedure
    OracleCommandBuilder.DeriveParameters(cmd)
    cmd.Parameters("in_transaction_id").Value = TransactionId
    cmd.ExecuteNonQuery()
    conn.Close()


Catch ex As Exception
   'PseudoCode:  if error is PasswordExpired->open the ChengePassForm...blah,blah
   'is handled by a Error class that i have
Finally
    If Not conn Is Nothing Then
        conn.Dispose()
    End If
End Try

Upvotes: 1

SLaks
SLaks

Reputation: 887547

You can make a function that takes an Action(Of OracleCommand).

Call the delegate in a Try Catch block, and, if the password changes, simply call the action again to re-run the code with the correct password.

You would call this function with a lambda expression.
Beware that everything in the lambda expression might run more than once.

Upvotes: 2

Related Questions