on 04-07-2014 5:18 PM
Good day together,
i work since two days on a problem - without any solution. Iam sure the solution is kind of easy, maybe one codeline.
I build up my RFC Connection with my Access-AddIn. In this Addin i have a simple module:
Public rfcLogon As Object
Public rfcConnection As Object
Public rfcFunctions As Object
Public rfcDataTable As Object
Function setRfcConnection() As Boolean
On Error Resume Next
Set rfcLogon = CreateObject("SAP.Logoncontrol.1")
Set rfcConnection = rfcLogon.NewConnection
rfcConnection.ApplicationServer = "XXXX"
rfcConnection.System = "XXXXX"
rfcConnection.SystemNumber = 46
rfcConnection.User = "XXXXX"
rfcConnection.Password = "XXXXXX"
rfcConnection.Client = "470"
rfcConnection.Language = "DE"
setRfcConnection = rfcConnection.Logon(0, True)
If Not setRfcConnection Then qp.RFC.rfcConnection.LastError
End Function
Sub closeRfcConnection()
If rfcConnection Is Nothing Then Exit Sub
rfcConnection.Logoff
Set rfcLogon = Nothing
Set rfcConnection = Nothing
End Sub
When i start a procedure like this:
Sub Test()
qp.RFC.setRfcConnection
qp.RFC.closeRfcConnection
qp.RFC.setRfcConnection
End Sub
... i get an error at the second call of setRfcConnection from the RFC:
Error Group
RFC_ERROR_SYSTEM_FAILURE
Message
>>> RfcOpenEx ...
Got following connect_param string:
USER=ME_CPIC CLIENT=470 LANG=DE PASSWD=******* <<< RfcOpenEx failed
I cant start a new Connection until i close Access and start it again. My first thoughts were this is because I did not reset the Object, but I did. Although I tried the .Logoff-Method. No solution 😕
Thanks a lot for any ideas and help.
PROBLEM SOLVED:
Option Explicit
Public rfcLogon As SAPLogonCtrl.SAPLogonControl
Public rfcConnection As SAPLogonCtrl.Connection
Function setRfcConnection() As Boolean
On Error Resume Next
If rfcLogon Is Nothing Then Set rfcLogon = CreateObject("SAP.Logoncontrol.1")
If rfcConnection Is Nothing Then Set rfcConnection = rfcLogon.NewConnection
rfcConnection.ApplicationServer = "xxx"
rfcConnection.System = "IC LMV - PS5 - Production"
rfcConnection.SystemNumber = 46
rfcConnection.User = "ME_CPIC"
rfcConnection.Password = ""
rfcConnection.Client = "470"
rfcConnection.Language = "DE"
setRfcConnection = rfcConnection.Logon(0, True)
If Not setRfcConnection Then rfcConnection.LastError
End Function
Sub closeRfcConnection()
If rfcConnection Is Nothing Then Exit Sub
rfcConnection.Logoff
End Sub
Sub Test()
Debug.Print setRfcConnection
closeRfcConnection
Debug.Print setRfcConnection
closeRfcConnection
End Sub
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just tried not to use the login-data in the source code and logon with the logon-pad instead:
Option Explicit
Public rfcLogon As SAPLogonCtrl.SAPLogonControl
Public rfcConnection As SAPLogonCtrl.Connection
Function setRfcConnection() As Boolean
On Error Resume Next
Set rfcLogon = CreateObject("SAP.Logoncontrol.1")
Set rfcConnection = rfcLogon.NewConnection
' rfcConnection.ApplicationServer = "xdsaasd"
' rfcConnection.System = "IC LMV - PS5 - Production"
' rfcConnection.SystemNumber = 46
' rfcConnection.User = "ME_CPIC"
' rfcConnection.Password = "sasa"
' rfcConnection.Client = "470"
' rfcConnection.Language = "DE"
' setRfcConnection = rfcConnection.Logon(0, True)
setRfcConnection = rfcConnection.Logon(0, False)
If Not setRfcConnection Then rfcConnection.LastError
End Function
Sub closeRfcConnection()
If rfcConnection Is Nothing Then Exit Sub
rfcConnection.Logoff
Set rfcLogon = Nothing
Set rfcConnection = Nothing
End Sub
Sub Test()
Debug.Print setRfcConnection
closeRfcConnection
Debug.Print setRfcConnection
closeRfcConnection
End Sub
.... and it works. I get two times "True" in the directwindow.
So whats wrong? Using the Login in the sourceode does not work. I also tried to wait a few minutes after the first connection attempt. anyway - the second attempt always fails.
Any ideas?
regards, Max
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Maximilian,
I check your code with a few little minor changes and it works perfect:
Public rfcLogon As SAPLogonCtrl.SAPLogonControl
Public rfcConnection As SAPLogonCtrl.Connection
Function setRfcConnection() As Boolean
On Error Resume Next
Set rfcLogon = CreateObject("SAP.Logoncontrol.1")
Set rfcConnection = rfcLogon.NewConnection
rfcConnection.ApplicationServer = "B7A"
rfcConnection.System = "B7A"
rfcConnection.SystemNumber = 43
rfcConnection.User = "Hugo"
rfcConnection.Password = "Bambi"
rfcConnection.Client = "111"
rfcConnection.Language = "DE"
setRfcConnection = rfcConnection.Logon(0, True)
If Not setRfcConnection Then rfcConnection.LastError
End Function
Sub closeRfcConnection()
If rfcConnection Is Nothing Then Exit Sub
rfcConnection.Logoff
Set rfcLogon = Nothing
Set rfcConnection = Nothing
End Sub
Sub Test()
setRfcConnection
closeRfcConnection
setRfcConnection
'No error here
closeRfcConnection
End Sub
I think it is an error outside of the code you presented here. Maybe in your qp class?
Cheers
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Good Morning Stefan,
thank you for your reply to my problem.
i copied your whole source in a new project. so no Addin is used....
I adjust my connection settings and added Debug.Print before the two Function-Calls of setRfcConnection. What I get in my Debug-Window is:
1: True
2: False
And the RFC-Error-Message on the second connection attempt:
Error Group
RFC_ERROR_SYSTEM_FAILURE
Message
>>> RfcOpenEx ...
Got following connect_param string:
USER=ME_CPIC CLIENT=470 LANG=DE PASSWD=******* <<< RfcOpenEx failed
When i close Excel and start it again, the first attempt works, the second throws an error.
i have no idea why. Annoying....!
Max
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.