on 01-27-2017 7:30 PM
Hello
I'm creating an addon and it's my first time using the DI API. Everything's working fine so far but whenever I try to debug the addon it takes up to 10 seconds to load the screen. That's because the connection is taking too long (oCompany var). I was wondering if there's a better way to get the oCompany var, maybe using SBO's current connection or something like that. My code is as follow:
private int SetConnectionContext()
{
int setConnectionContextReturn = 0;
string sCookie = null;
string sConnectionContext = null;
// First initialize the Company object
oCompany = new SAPbobsCOM.Company();
// Acquire the connection context cookie from the DI API.
sCookie = oCompany.GetContextCookie();
// Retrieve the connection context string from the UI API using the
// acquired cookie.
sConnectionContext = Application.SBO_Application.Company.GetConnectionContext(sCookie);
// before setting the SBO Login Context make sure the company is not
// connected
if (oCompany.Connected == true)
{
oCompany.Disconnect();
}
// Set the connection context information to the DI API.
setConnectionContextReturn = oCompany.SetSboLoginContext(sConnectionContext);
return setConnectionContextReturn;
}
private int ConnectToCompany()
{
int connectToCompanyReturn = 0;
// Establish the connection to the company database.
connectToCompanyReturn = oCompany.Connect();
return connectToCompanyReturn;
}
Hi Rudá,
I usually do this:
SAPbouiCOM.SboGuiApi oSboGuiApi = new SAPbouiCOM.SboGuiApi();
try
{
// Connect in a SAP Application
oSboGuiApi.Connect(param);
SBO_Application = oSboGuiApi.GetApplication(-1);
SBO_Application.StatusBar.SetText("Add-on connected: " + appName, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
SBO_Company = SBO_Application.Company.GetDICompany();
}
catch (Exception ex)
{
Log.WriteExceptionLog(ex.Message, ex, this);
System.Windows.Forms.MessageBox.Show("It was not possible to connect to SAP Business One: " + ex.Message, "Connection Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
System.Environment.Exit(0);
}
Hope it helps.
Kind Regards,
Diego Lother
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
98 | |
11 | |
11 | |
6 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.