cancel
Showing results for 
Search instead for 
Did you mean: 

DI API: connect to other company with User and Password

Former Member
0 Kudos
using System;
using System.Collections.Generic;
using System.Xml;
using SAPbouiCOM.Framework;


namespace SBOAddonProject_B1Connect
{
    [FormAttribute("SBOAddonProject_B1Connect.Form1", "Form1.b1f")]
    class Form1 : UserFormBase
    {


        private SAPbouiCOM.EditText CFL_CMP;
        private SAPbouiCOM.EditText User;
        private SAPbouiCOM.EditText pwd;
        private SAPbouiCOM.Button BTNChange;
        private SAPbouiCOM.Button Button1;
        private SAPbouiCOM.StaticText StaticText0;
        private SAPbouiCOM.StaticText StaticText1;
        private SAPbouiCOM.StaticText StaticText2;


        public  SAPbobsCOM.Company otherCompany = new SAPbobsCOM.Company();
        public Form1()
        {
            otherCompany.Server =  Program.oCompany.Server;
            otherCompany.CompanyDB = Program.oCompany.CompanyDB;
            otherCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
            otherCompany.DbUserName = Program.oCompany.DbUserName;
            otherCompany.DbPassword = Program.oCompany.DbPassword;
            otherCompany.language = SAPbobsCOM.BoSuppLangs.ln_English;


        }


       
        public override void OnInitializeComponent()
        {
            this.CFL_CMP = ((SAPbouiCOM.EditText)(this.GetItem("CFL_CMP").Specific));
            this.User = ((SAPbouiCOM.EditText)(this.GetItem("User").Specific));
            this.pwd = ((SAPbouiCOM.EditText)(this.GetItem("pwd").Specific));
            this.BTNChange = ((SAPbouiCOM.Button)(this.GetItem("BTNChange").Specific));
            this.BTNChange.ClickBefore += new SAPbouiCOM._IButtonEvents_ClickBeforeEventHandler(this.BTNChange_ClickBefore);
            // this.Button0.ClickBefore += new SAPbouiCOM._IButtonEvents_ClickBeforeEventHandler(this.Button0_ClickBefore);
            this.Button1 = ((SAPbouiCOM.Button)(this.GetItem("2").Specific));
            this.StaticText0 = ((SAPbouiCOM.StaticText)(this.GetItem("Item_5").Specific));
            this.StaticText1 = ((SAPbouiCOM.StaticText)(this.GetItem("Item_6").Specific));
            this.StaticText2 = ((SAPbouiCOM.StaticText)(this.GetItem("Item_7").Specific));
            this.OnCustomInitialize();

        }

        private void BTNChange_ClickBefore(object sboObject, SAPbouiCOM.SBOItemEventArg pVal, out bool BubbleEvent)
        {
            BubbleEvent = true;
            //BubbleEvent = true;
            otherCompany.UserName = User.ToString();
            otherCompany.Password = pwd.ToString();
            string error = string.Empty;
            int iErr;
            if (otherCompany.Connect() != 0 )
            {
                Program.oCompany.GetLastError(out iErr, out error);
                if (iErr == -111)
                {
                    Application.SBO_Application.MessageBox("Wrong database password");
                }
                else if (iErr == -107)
                {
                    Application.SBO_Application.MessageBox("Wrong company password");
                }
                else
                {
                    Program.SBO_Application.StatusBar.SetText(""+Program.oCompany.GetLastErrorDescription()+ Program.oCompany.GetLastErrorDescription(), SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
                }
            }
            else
            {
                //Connected
                Program.SBO_Application.StatusBar.SetText("Connected", SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
            }
        }
    }
}





And Getting Error 'the function requires all threads to run'

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member185682
Active Contributor
0 Kudos

Hi Dhruv,

This line should'nt work:

otherCompany.DbPassword = Program.oCompany.DbPassword;

The SDK doesn't provide the password of the database user.

Did you try to replace the lines:

otherCompany.DbUserName =Program.oCompany.DbUserName;
otherCompany.DbPassword =Program.oCompany.DbPassword;

By the instruction:

otherCompany.UseTrusted = true;

Hope it helps.

Kind Regards,

Diego Lother

Former Member
0 Kudos

Hi DIEGO LOTHER

Thank you for resopons not work still ..... Getting same error when initialize ('the function requires all threads to run')

'otherCompany.CompanyDB =Program.oCompany.CompanyDB;' at left hand side in .Net and SDK will give me DBName when i logged in B1 also password but look like ******** when it initialized.

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Dhruv,

Try to login to DTW for the affected company for which you are getting the error and collect all required parameters in order to make the connection in DTW. After that try the same with DI API.

In this piece of code, can you try to enter LicenseServer or SLDServer property and check the connection?

oCompany.SLDServer = "https://<Server-name>:40000/"

You will be able to use SLDServer property, if you will be using 9.2 PL05 or above.

Hope it helps.

Kind regards,

ANKIT CHAUHAN

SAP SME Support

former_member185682
Active Contributor
0 Kudos

Hi Dhruv,

The password look like "******" because the SDK doesn't provide the password for security reasons. In this case when you need connect on the database with another user, I suggest to use the property UseTrusted = true.

P.S: I provide a more detailed response on your second post.

Hope it helps.

Kind Regards,

Diego Lother