1

I have a .Net application which use to create SAP sales orders through it. When I use a (common)single SAP user id to login to the rfcDestination it works perfectly. but it doesnt work with concurrent logins with different user id's. i see 2 case:

1) when i have logged in using a user id say test1(SAP user) it connects successfully.

2)when i login with different user and with incorrect password , it still connects.

I do not want to unregister test1 session as i want concurrent logins at same time. How do i achieve this. Below is the code i have tried so far

 SAPConnection objDestConfig = new SAPConnection();
 objDestConfig.AddOrEditDestination(appserver, Name, instanceno, systemid, txt_user.Text, 
txt_password.Text, client, "E");
                    RfcDestination prd = RfcDestinationManager.TryGetDestination(Name);

                    if (prd == null)
                    {
                        RfcDestinationManager.RegisterDestinationConfiguration(objDestConfig);
                        prd = RfcDestinationManager.GetDestination(Name);

                    }
                    //   }


                    //Establishing connection with SAP system
                    // RfcDestination dest = RfcDestinationManager.GetDestination(Name);
                    prd.Ping();   //always returns true even for incorrect password if the destination is registered.

 public SAPConnection()
    {
        //check for available SAP destinations
        availableDestinations = new Dictionary<string, RfcConfigParameters>();
    }

    public RfcConfigParameters GetParameters(string destinationName)
    {
        //reading current SAP destination configurations
        RfcConfigParameters foundDestination;
        availableDestinations.TryGetValue(destinationName, out foundDestination);
        return foundDestination;
    }

    public bool ChangeEventsSupported()
    {
        return true;
    }

    public event RfcDestinationManager.ConfigurationChangeHandler ConfigurationChanged
    {
        add
        {
            changeHandler = value;
        }
        remove
        {                
        }
    }

    //removes the destination that is known under the given name
    public void RemoveDestination(string name)
    {
        if (name != null && availableDestinations.Remove(name))
        {
            changeHandler(name, new RfcConfigurationEventArgs(RfcConfigParameters.EventType.DELETED));
        }
    }

    //allows adding or modifying a SAP destination for a specific application server
    public void AddOrEditDestination(string appserver, string name, string systemnumber, string systemid, string user, string password, string client, string language)
    {            
        RfcConfigParameters parameters = new RfcConfigParameters();
        parameters[RfcConfigParameters.Name] = name;            
        parameters[RfcConfigParameters.User] = user;
        parameters[RfcConfigParameters.Password] = password;
        parameters[RfcConfigParameters.Client] = client;
        parameters[RfcConfigParameters.Language] = language;
        parameters[RfcConfigParameters.AppServerHost] = appserver;
        parameters[RfcConfigParameters.SystemNumber] = systemnumber;
        parameters[RfcConfigParameters.SystemID] = systemid;
        RfcConfigParameters existingConfiguration;            
        if (availableDestinations.TryGetValue(name, out existingConfiguration))
        {
            //modifying SAP destination
            //if a destination of that name existed before, we need to fire a change event
            availableDestinations[name] = parameters;
            RfcConfigurationEventArgs eventArgs = new RfcConfigurationEventArgs(RfcConfigParameters.EventType.CHANGED, parameters);
            changeHandler(name, eventArgs);
        }
        else
        {
            //adding new SAP destination
            availableDestinations[name] = parameters;
        }
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Aswini
  • 51
  • 4
  • 16
  • NCo probably uses the connection it already has. If it has the same name, NCo probably doesn't recognize the changed username and password. You will probably need to register a bunch of destinations with the DestinationManager and implement a manual pooling that takes the username in consideration when looking for the destination to use. – Dirk Trilsbeek Jan 14 '20 at 09:12
  • i have used with different names for each user..still it takes incorrect password and logs in. – Aswini Jan 16 '20 at 08:46
  • I resolved this issue by using RfcCustomDestination class which checks for the concurrent user names and passwords. RfcDestination dest = RfcDestinationManager.GetDestination("SAPConnection"); RfcCustomDestination temp = dest.CreateCustomDestination(); temp.User = txt_user.Text; temp.Password = txt_password.Text;If the password is wrong then Dest.ping throws an error. – Aswini Jan 31 '20 at 07:48

1 Answers1

0

This is a usecase of RfcCustomDestination. Create one RfcDestination that has only parameters like AppServerHost, SystemNumber, etc. but not User, Password, Client and Language. This can be viewed as a "base destination".

Then for every end-user that logs into your application, create a new RfcCustomDestination object from the "base destination", where you mix in the current user's special parameters User, Password, Client and Language. (You probably obtain these from the end-user by prompting some kind of "login dialog" to him.

Lanzelot
  • 15,976
  • 4
  • 18
  • 14