Skip to Content
0
Sep 10, 2020 at 09:50 AM

WSAECONNRESET - How can I get this error on VBA or VBS Scripts

245 Views Last edit Sep 10, 2020 at 09:53 AM 2 rev

Hi, I am simulating the following:

Open one or more SAP session and afterwards switch off the connection (with can happen)
System will pop up the Message Box: WSAECONNRESET: Conection Reset by Peer.

When I run any VBA or VBS Script it looks "OK" because system still considering the SAP Logon Window Opened and also a SAP session active.

Basically all objects (I am considering) are still valid.

Do you know any way to get this error on in order to kill SAP run (like in task manager) or any order way?
and restablish a new conection?

I am using an example got from StackOverflow, but I have tested many others with similar results"

Exemple here:

Sub sap()

If SAP_Connection Then
MsgBox ("Sap is Open so just attached to session(0)")
Else
MsgBox ("Sap is NOT open so open Logon Window")
End If

End Sub
Function SAP_Connection() As Boolean

On Error GoTo ErrSap


If Not IsObject(SapApplication) Then
   Set SapGuiAuto = GetObject("SAPGUI")
   Set SapApplication = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
   Set connection = SapApplication.Children(0)
End If
If Not IsObject(session) Then
   Set session = connection.Children(0)
End If
If IsObject(WScript) Then
   WScript.ConnectObject session, "on"
   WScript.ConnectObject SapApplication, "on"
End If
   Set session = Nothing
SAP_Connection = True
Exit Function


ErrSap:
SAP_Connection = False

End Function

Thanks and appreciate any help on this.

Attachments