NRDargie
NRDargie

Reputation: 25

SAP NCo multiple connections issue, one login after create function call one again after invoke call

I'm trying to achieve the following, but with using only one connection so as to avoid breaking the SAP license where you're only allowed to have the same user logged on once.

I'm using the sapnco.dll and sapnco_util.dll version 3.0.

The following code shows the issue. Two connections get generated. One when the call to CreateFunction is made and another one when the Invoke call is made.

RfcDestinationManager.RegisterDestinationConfiguration(new SapConnection("test"));
        ExampleSessionProvider sessionProvider = new ExampleSessionProvider();
        sessionProvider.SetSession(sessionProvider.CreateSession());
        RfcSessionManager.RegisterSessionProvider(sessionProvider);
        
StringBuilder result = new StringBuilder();

        var destination = RfcDestinationManager.GetDestination("test");
        RfcSessionManager.BeginContext(destination);
        var function = destination.Repository.CreateFunction("Z_PKUK01_ZDC_ENGINE_CALLH");
        var requestTable = function.GetTable("ITAB_REQUEST");
        requestTable.Append();
        requestTable.SetValue("LINE", "TestMessage");
        function.Invoke(destination);
        RfcSessionManager.EndContext(destination);
        var responseTable = function.GetTable("OTAB_RESPONSE");
        var row = responseTable.CurrentRow;
        var rowval = row.GetValue("LINE").ToString();
        result.Append(row.GetValue("LINE").ToString()
            .Substring(0, Math.Min(rowval.Length, result.Capacity)));

Upvotes: 0

Views: 1076

Answers (1)

Trixx
Trixx

Reputation: 1885

SAP NCo will always use different pools for repository calls and business application calls. That means it will need at least 2 connections if you are working with a standard dynamic repository. I am wondering if this would really break your SAP license as this is the recommended and standard way of using the SAP .NET Connector. Are you sure about this?

However, the repository connection won't be needed anymore after all RFC meta data have been queried. So it will be closed soon afterwards and never reopened again if you don't need further meta data. So you can wait until the repository pool closes the connection with defining a short ConnectionIdleTimeout - ideally via a separate destination configuration only used for repository meta data queries. Or - after having obtained the RfcRepository instance and the IRfcFunction object - you actively delete the repository destination via IDestinationConfiguration.ConfigurationChanged event which should also close all pooled connections immediately. Alternatively, you can also work with a static RfcCustomRepository and serialized/stored meta data where no connection for retrieving the RFC meta data would be required at all. But this approach has the disadvantage not to be so flexible anymore against function interface modifications at ABAP system side.

But again: I doubt that your standard approach would really violate the SAP license. However, I am also no lawyer.

PS: Your declaration of a stateful call context is superfluous in your example and should be avoided if not really needed.

Upvotes: 2

Related Questions