4 Replies Latest reply on Mar 25, 2002 9:02 PM by 228301

    Error Trapping

    228301
      I am unable to trap run time errors. The "On Error" statements does not seems to work. I've tried both "GOTO label" and "Resume Next". But when the user/password is wrong or the user have no access to the table. VB trapped the error and never pass the control to my "IF" statement. For example:

      Dim sesOra As New OraSessionClass
      Dim dbOra As OraDatabase
      Dim rsOraLC As OraDynaset

      On Error Resume Next

      Set dbOra = sesOra.OpenDatabase(xDBserver, xUserId & "/" & xPassword, ORADB_ORAMODE)
      If Err.Number > 0 Then
      Msgbox Err.Description,vbCritical
      Exit Sub
      End If

      Me.Language_Prim.RowSource = ""
      Me.Language_Prim.RowSource = ""
      Set rsOraLC = dbOra.CreateDynaset("SELECT * FROM dbo.Language_Control", ORADYN_READONLY)

      If Err.Number > 0 Then
      Msgbox Err.Description,vbCritical
      Exit Sub
      End If
      rsOraLC.MoveFirst
      Do While Not rsOraLC.EOF
      If Me.Language_Prim.RowSource = "" Then
      Me.Language_Prim.RowSource = rsOraLC.Fields("TX_language").Value & ";" & rsOraLC.Fields("CD_Language").Value
      Else
      Me.Language_Prim.RowSource = Me.Language_Prim.RowSource & ";" & rsOraLC.Fields("TX_language").Value & ";" & rsOraLC.Fields("CD_Language").Value
      End If
      rsOraLC.MoveNext
      Loop
        • 1. re:Error Trapping
          152901
          Prior to calling and after calling the CreateDynaset method use the LastServerErr functionality as such...

          dbOra.LastServerErrReset 'Clear Error on Oracle OLE Object

          Set rsOraLC = dbOra.CreateDynaset("SELECT * FROM dbo.Language_Control", ORADYN_READONLY)

          'Force Error Handling for Oracle
          If Not (dbOra.LastServerErr = 0) Then
          Err.Raise 440, "Oracle Automation (OO4O)", _
          "( " & dbOra.LastServerErr & " ) - " & _
          dbOra.LastServerErrText & vbLf & _
          "Position: " & dbOra.LastServerErrPos
          End If



          Do note, there are three diferent ways OO4O traps errors that may not be seen by the hosting langauge. The two most common being LastServerErr on both the Session and Database objects. The least know is the LastErrorText property of the OraParamArray object.

          Zane E
          • 2. re:Error Trapping
            228301
            I tried the code but it doesn't seems to work. Let me clarify my problem. It is with "OpenDatabase". When I entered the wrong password. VB trapped the error and display the standard error pop-up panel showing "Runtime Error 440:" with the appropriate ORACLE error message. I would like to trap it and prompt the user to re-enter the userid/password. I'm just wondering if there's a set of command to tell VB to not trap the OO4O errors and let the application handle it?

            Regards,
            Jason Fenixdy

            P.S. I'm using VB under Access 2000.
            • 3. re:Error Trapping
              152901
              Do the On Error Resume Next as you were and test the LastServerErr property for the value of '1017' (ORA-01017) after your OpenDatabase call.

              Good Luck

              Zane E
              • 4. re:Error Trapping
                228301
                The problem was setting in MS Access. Somehow on my machine the Error Trapping 'Option' is set to Trap all error. Everything worked like a charm after I changed it to 'Trap Only Unhandled Error'.