cancel
Showing results for 
Search instead for 
Did you mean: 

SDK Connection Settings Question

Former Member
0 Kudos

Hi,

Im currently developing some Add-ons for our company and just had a question about the connection to the database.

Im currently using the following method to open a connection to the SAP database.


                    

oCompany = new SAPbobsCOM.Company();

oCompany = (SAPbobsCOM.Company)Application.SBO_Application.Company.GetDICompany();

oCompany.Connect();

if (oCompany.Connected == true)

{

     // Execute some code

}

What I have found is it takes quite some time to open this connection. I see this is an issue quite a few people have. So I think I should open the connection only once, and keep it persistent whilst the add-on is running.

I have thought about placing it in the SBO_Application_FormDataEvent, but perhaps some one has a better solution?

Regards

Accepted Solutions (1)

Accepted Solutions (1)

pedro_magueija
Active Contributor
0 Kudos

Hi Edward,

Access to the event you mentioned requires a UI API connection. Placing a connection on the event is a bad idea (you'll be connection everytime the event is triggered, soon you'll run out of memory).

Assuming you already have the UI API connection you can pull the company object from that connection:


try

{

    var gui = new SboGuiApi();

    gui.Connect(connectionString);

    application = gui.GetApplication();

    company = new Company { Application = application };

    company.Connect();

}

catch (COMException e)

{

    throw ConnectionException.CreateFrom(e);

}

Best practice to establish connection to SAP Business One is at the addon startup. Should be the very first thing you do. Store the reference to your company and application objects (perhaps in a globally accessible place) and you should be fine.

Good luck.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Answers (1)

Answers (1)

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Edward,

You can refer to SAP Business One SDK Help Center or you can refer to SDK Samples for the same.

You can try to use the Single Sign On or you can go with the Classic Connection also.

Kind regards,

ANKIT CHAUHAN

SAP Business One Global Support