Skip to Content
0

DI API Connection in Production Environment

Nov 25, 2016 at 02:56 PM

299

avatar image

Today I wanted to install the first version of our addon in our Company, but I found out that the addon have a dependency of a DI API Config file, while it shouldn't.

On the computer I developed the addon works fine, but after I added the addon in the addon manager and I tried to run it on a few other computer (it installed fine), it threw an exception 'Couldn't connect to the Licence server..'. After a few tries and a version which prints to the console, I figured it it tires to connect with 'localhost:30000'. This address is provided to the SAP in the config file here: ''C:\Program Files (x86)\SAP\SAP Business One DI API\Conf\b1-local-machine.xml', saying:

<leaf kind="single" name="LicenseServer" type="String">
    <value>localhost:30000</value>
</leaf>

If I change it to our company's server ip, my addon works. My problem is that every new installation of the SAP B1 client will have the DI API's config set to localhost and I need to manually change it everytime. It is bothersome at least.

Other thing is we have two other addons which are not developed by me and are perfectly fine with the localhost address. So I am guessing I am doing something wrong (I followed the sample file though)

Here is the class I am using as a base class and every class that would use DI API inherit this:

public class SAPDIDao
{
    private static Company savedCompany = null;

    protected SAPbouiCOM.Application SBOApp = null;
    protected Company oCompany = null;

    public SAPDIDao(SAPbouiCOM.Application SBOApp)
    {
        this.SBOApp = SBOApp;
        this.oCompany = GetCompany(SBOApp);
    }

    public static Company GetCompany(SAPbouiCOM.Application SBOApp)
    {
        if (savedCompany == null)
        {
            Company tmpCompany = new Company();
            int contextCode = SetConnectionContext(SBOApp, tmpCompany);
            int errorCode = tmpCompany.Connect();
            Console.WriteLine("Connection to Licence server: " + tmpCompany.LicenseServer);
            if (errorCode != 0)
            {
                string lastException = "";
                tmpCompany.GetLastError(out errorCode, out lastException);
                Console.WriteLine("Company connect error: " + errorCode + ", msg: " + lastException);
                tmpCompany.GetLastError(out errorCode, out lastException);
                Console.WriteLine("Context: " + contextCode + ", msg: " + lastException);
                throw new Exception("Company connect error: " + errorCode + ", msg: " + lastException + "\nContext: " + contextCode + ", msg: " + lastException);
            }
            savedCompany = tmpCompany;
        }
        return savedCompany;
    }

    private static int SetConnectionContext(SAPbouiCOM.Application SBOApp, Company tmpCompany)
    {
        int setConnectionContextReturn = 0;
        string sCookie = tmpCompany.GetContextCookie();
        string sConnectionContext = SBOApp.Company.GetConnectionContext(sCookie);

        if (tmpCompany.Connected)
        {
            tmpCompany.Disconnect();
        }
        setConnectionContextReturn = tmpCompany.SetSboLoginContext(sConnectionContext);

        Console.WriteLine("DI API Connection, login context: " + setConnectionContextReturn);
        return setConnectionContextReturn;
    }
}

I am using SAP B1 9.2 and I tried with both the seperate ui/di dlls and the new one, which provides both as a single dll.

Also, I posted a Question about this already in the Past, but the solution there lead me to this problem:

https://archive.sap.com/discussions/thread/3964295

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
DIEGO LOTHER Nov 25, 2016 at 05:29 PM
1

Hi Szabolcs,

Did you try to use GetDICompany() from Company object from Application object?

Instead of use your code above, follow this sample:

I always use this method to get DI company object on my add-ons and I never had problems.

Hope it helps.

Kind Regards,

Diego Lother


img.png (53.6 kB)
Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thank you, this solves my issue completely and the addon's process only uses around ~20MB of memory instead of ~120MB.

0
Pedro Magueija Nov 29, 2016 at 03:34 PM
1

Hi Szabolcs,

I've switched from that method after a source at SAP told me that it can cause issues with deadlocks (or at least increase their occurrence).

Your mileage may vary.

Pedro Magueija

LinkedIn | Twitter | Blog

Share
10 |10000 characters needed characters left characters exceeded
Ad Kerremans Nov 28, 2016 at 11:49 AM
0

Hi,

This solution works, but the performance of DI-API calls will be less because every call is now a RPC call instead of a COM-call.

Kind Regerds,

Ad

Show 1 Share
10 |10000 characters needed characters left characters exceeded

You mean the code I posted is the slower and the 'GetDICompany()' is faster, or the other way?

0
Ad Kerremans Nov 28, 2016 at 01:52 PM
0

Iit is the other way, GetDICompany() is the slower way.

Kind Regards

Ad

Show 2 Share
10 |10000 characters needed characters left characters exceeded

I see, thanks. I just got confused, becouse you posted your reply as an answer.

0

Hi Ad,

I always used GetDICompany(). I never had tested the other way, but even that GetDICompany() method is slower than other way, I never had performance problem with GetDICompany().

Kind Regards,

Diego Lother

0