cancel
Showing results for 
Search instead for 
Did you mean: 

DI API Connection in Production Environment

former_member231954
Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member185682
Active Contributor

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

former_member231954
Participant
0 Kudos

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

Answers (3)

Answers (3)

pedro_magueija
Active Contributor

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

AdKerremans
Active Contributor
0 Kudos

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

Kind Regards

Ad

former_member231954
Participant
0 Kudos

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

former_member185682
Active Contributor
0 Kudos

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

AdKerremans
Active Contributor
0 Kudos

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

former_member231954
Participant
0 Kudos

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