Skip to Content
Nov 25, 2016 at 02:56 PM

DI API Connection in Production Environment

1163 Views Last edit Nov 25, 2016 at 03:00 PM 2 rev

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">

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)
        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: