IBM Support

Automation Objects Intermittently Fail: -2147467259: Unspecified Error

Troubleshooting


Problem

Programs written with the IBM i Access Client Solutions Windows Application Package automation objects might intermittently fail with error -2147467259: Unspecified Error. This error can be caused by a communication error; it can be detected and recovery attempted.

Resolving The Problem

An application is written using the IBM i Access Client Solutions Windows Application Package ActiveX Automation Object library (cwbx.dll). The application uses the System object to make a connection and then repeatedly calls the Call method of the Program object. The application intermittently fails with the following error: 2147467259 - Unspecified error.  The System object and Program object have no errors in their error collection. Both objects have return codes of 0. The application is unable to recover from the failure and continues to generate errors.

The problem is caused by a communications failure. The communications error can be caused by a network error (inactivity timer, busy network, etc.) or by a IBM i administrator ending the host server jobs. The cwbx objects map the communications error to the generic automation error Unspecified Error. Applications running in an unattended environment might need to monitor for and handle this error. The following code example shows how an application might detect and attempt to recover from this error.

Sub MySub()
Dim as400 As New cwbx.AS400System
Dim RPGTST As New cwbx.Program
...
On Error Goto DspErr
...

DspErr:
   Dim cwbErr As cwbx.Error
   Dim S As String
   Dim errNum As Integer
   
   'Log the error information
   S = "Error " & Err.Number & ": " & Err.Description & vbCrLf & vbCrLf
   If RPGTST.Errors.Count <> 0 Then
      For Each cwbErr In RPGTST.Errors
         S = S & "Pgmerr " & cwbErr.Text & vbCrLf
      Next cwbErr
   End If
   If as400.Errors.Count <> 0 Then
      For Each cwbErr In as400.Errors
         S = S & "as400Err " & cwbErr.Text & vbCrLf
      Next cwbErr
   End If
   Debug.Print S
   Debug.Print as400.IsConnected(cwbcoServiceRemoteCmd)
   
   If as400.IsConnected(cwbcoServiceRemoteCmd) = 0 And Err.Number = -2147467259 Then
      If ReConnect(as400) = False Then
         MsgBox "Unable to reconnect"
         Exit Sub
      Else
         Resume
      End If
   Else
      MsgBox "Unhandled error: " & S
   End If
''''''''''''''''''''''''''''''''''''''''''''''

Function ReConnect(ByRef as400 As cwbx.AS400System) As Boolean
Dim I As Integer

On Error Resume Next

'Attempt to reconnect until either:
'- We are able to reconnect
'- max tries is reached
Do
   If I <> 0 Then
      Sleep RETRYWAIT    'pause before another attempt
   End If
   I = I + 1
   as400.Disconnect (cwbcoServiceAll)  'Must decrement use count to 0 before reconnecting.
   as400.Connect cwbcoServiceRemoteCmd
Loop While as400.IsConnected(cwbcoServiceRemoteCmd) = 0 And I < MAXRECONNECT

If as400.Errors.ReturnCode = 0 And as400.IsConnected(cwbcoServiceRemoteCmd) = 1 Then
   ReConnect = True
   Exit Function 'reconnected
Else
DspErr:
   Dim cwbErr As cwbx.Error
   Dim S As String
   Debug.Print as400.Errors.ReturnCode
   For Each cwbErr In as400.Errors
         S = S & cwbErr.Text & vbCrLf
   Next cwbErr
   ReConnect = False
End If

End Function
[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG60","label":"IBM i"},"Component":"Data Access","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}}]

Historical Number

335373648

Document Information

More support for:
IBM i

Software version:
All Versions

Operating system(s):
IBM i

Document number:
639195

Modified date:
26 December 2019

UID

nas8N1016136

Manage My Notification Subscriptions