1

I want to save different SAP users to a database and check with a SAP login if the input was correct. For the login, I have to use the SAP.net Connector3.0.

Procedure: click button -> enter user1 -> SAP login -> if correct: save, else errormessage -> SAP logout -> click button again-> enter user2 -> Sap login ->...and so on

My code:

Private Sub ButtonSaveUser_Click(sender As Object, e As EventArgs) Handles ButtonSaveUser.Click

    Try
        Dim parms As New RfcConfigParameters
        parms.Add(RfcConfigParameters.User, TextBoxUser.Text)
        parms.Add(RfcConfigParameters.AppServerHost, TextBoxRouter.Text)
        parms.Add(RfcConfigParameters.SystemNumber, TextBoxSystemnumber.Text)
        parms.Add(RfcConfigParameters.SystemID, TextBoxSystem.Text)
        parms.Add(RfcConfigParameters.Password, TextBoxPasswort.Text)
        parms.Add(RfcConfigParameters.Client, TextBoxClient.Text)
        parms.Add(RfcConfigParameters.Language, TextBoxLanguage.Text)
        parms.Add(RfcConfigParameters.Name, "Connection Name")

        Dim dest As RfcDestination = RfcDestinationManager.GetDestination(parms)
        Dim repo As RfcRepository = dest.Repository

' in this space is the part where I save the user information. this works.

    Catch ex As Exception
        MsgBox("Logon failed.  " + ex.Message)
    End Try
End Sub

Question: What do I have to write at the end of my code to logout or disconnect? I thought that there might be something like a 'dest.disconnect' command, but i can't find such a command.

(My problem is, that I'm new at programming and don't know how to implement the missing parts.)

If anybody could post a vb code or give any other information, that would be awesome! Thanks :)

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Ben
  • 11
  • 1
  • 4
  • This question is mildly unclear - as well as incomplete. You have not shown us what you have tried as far as the proposed issue. – Der Kommissar Apr 23 '15 at 15:39

2 Answers2

1

I have never bothered. I let the Destination manager manage the connections. but there is an option to unregister destinations. You could trying that

public static void UnregisterDestinationConfiguration(IDestinationConfiguration config)

but i was under the impression the session manager should manage things eg:
EDITED to reflect comments

   var parms = new RfcConfigParameters();
   // the connection params are set .....
   //parms.xxx = 
   RfcDestination _dest;
   _dest = RfcDestinationManager.GetDestination(parms);

   IRfcFunction func = _dest.Repository.CreateFunction("Z_MY FUNC"); 
 RfcSessionManager.BeginContext(_dest);
 func.Invoke(_dest);
 RfcSessionManager.EndContext(_dest);

my point was more of contrasting logon version a destination that the Session manager managers for you.

phil soady
  • 11,043
  • 5
  • 50
  • 95
  • Unfortunately your code is in c#. I tried to use it, but I don't know what I have to write for: func.Invoke(_dest); i get the massage: no "func" was found – Ben Apr 23 '15 at 18:47
  • func is variable. Not shown you have a function you want to call. Ill add some more to code – phil soady Apr 24 '15 at 07:39
  • I can't get your code to work. It doesn't disconnect. I posted my solution in a new answer. thanks anyway. – Ben Apr 24 '15 at 14:04
  • You example is calling UnregisterDestinationConfiguration as I suggested. You also remove the destinate. That is an extra step. The code example shows the method signature that can be called not the calling it. – phil soady Apr 24 '15 at 14:19
0

I solved my problem with the following code:

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports SAP.Middleware.Connector

Public Class Form
Public Sub Buttonsaveuser_Click(sender As Object, e As EventArgs) Handles Buttonsaveuser.Click
    Dim objDestConfig As New InMemoryDestinationConfiguration
    Try
        Dim parms As New RfcConfigParameters
        parms(RfcConfigParameters.User) = TextBoxUser.Text
        parms(RfcConfigParameters.AppServerHost) = TextBoxRouter.Text
        parms(RfcConfigParameters.SystemNumber) = TextBoxSystemnumber.Text
        parms(RfcConfigParameters.SystemID) = TextBoxSystem.Text
        parms(RfcConfigParameters.Password) = TextBoxPasswort.Text
        parms(RfcConfigParameters.Client) = TextBoxClient.Text
        parms(RfcConfigParameters.Language) = TextBoxLanguage.Text
        parms(RfcConfigParameters.Name) = TextBoxDestination.Text

        RfcDestinationManager.RegisterDestinationConfiguration(objDestConfig)
                    objDestConfig.AddOrEditDestination(parms)

                    Dim destination1 As RfcDestination = RfcDestinationManager.GetDestination(TextBoxDestination.Text)
        destination1.Ping()



    Catch ex As Exception
        MsgBox("Logon failed.  " + ex.Message)
    Finally
                RfcDestinationManager.UnregisterDestinationConfiguration(objDestConfig)
        objDestConfig.RemoveDestination(TextBoxDestiantion.Text)
    End Try
End Sub

End Class







Public Class InMemoryDestinationConfiguration
Implements IDestinationConfiguration
    Private availableDestinations As Dictionary(Of String, RfcConfigParameters)

Public Sub New()
    availableDestinations = New Dictionary(Of String, RfcConfigParameters)()
End Sub

Public Function GetParameters(ByVal destinationName As String) As RfcConfigParameters _
    Implements IDestinationConfiguration.GetParameters
            Dim foundDestination As RfcConfigParameters = Nothing
    availableDestinations.TryGetValue(destinationName, foundDestination)
    Return foundDestination
End Function

Public Function ChangeEventsSupported() As Boolean _
    Implements IDestinationConfiguration.ChangeEventsSupported
            Return True 
End Function

Public Event ConfigurationChanged As RfcDestinationManager.ConfigurationChangeHandler _
    Implements IDestinationConfiguration.ConfigurationChanged


Public Sub AddOrEditDestination(ByVal parameters As RfcConfigParameters)
            Dim name As String = parameters(RfcConfigParameters.Name)

    If availableDestinations.ContainsKey(name) Then
        Dim EventArgs As New RfcConfigurationEventArgs(RfcConfigParameters.EventType.CHANGED, parameters)
        RaiseEvent ConfigurationChanged(name, EventArgs)
    End If

            availableDestinations(name) = parameters
    Dim tmp As String = "Application server"
    Dim isLoadValancing As Boolean = parameters.TryGetValue(RfcConfigParameters.LogonGroup, tmp)
    If isLoadValancing Then
        tmp = "Load balancing"
    End If

End Sub

Public Sub RemoveDestination(ByVal name As String)

    If availableDestinations.Remove(name) Then

        RaiseEvent ConfigurationChanged(name, New RfcConfigurationEventArgs(RfcConfigParameters.EventType.DELETED))

    End If
End Sub
end class
Ben
  • 11
  • 1
  • 4