on 09-10-2020 10:50 AM
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"
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.
You can use the DestroySession Even.
This event is raised before a session is destroyed . This can be done either by closing the main window manually, or by calling the closeSession method of GuiConnection.
Syntax
Visual Basic
Public Event DestroySession( _
ByVal Session As GuiSession _
)
Example
You can handle this event from VBScript by adding the following procedure:
Dim objSapGui
Set objSapGui = GetObject("SAPGUI")
Dim objScriptingEngine
Set objScriptingEngine =
objSapGui.GetScriptingEngine
WScript.ConnectObject objScriptingEngine, "Engine_"
Dim Waiting
Waiting = 1
Do While (Waiting = 1)
WScript.Sleep(100)
Loop
Set objScriptingEngine = Nothing
Set objSapGui = Nothing
Sub
Engine_CreateSession(ByVal Session)
Dim result
result = MsgBox("Session created", vbOKCancel)
If result = vbCancel then
Waiting = 0
End If
End Sub
Sub Engine_DestroySession(ByVal Session)
Dim result
result = MsgBox("Session destroyed",vbOKCancel)
If result = vbCancel then
Waiting = 0
End If
End Sub
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
102 | |
12 | |
11 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.