Skip to Content
avatar image
Former Member

DI API: connect to other company with User and Password

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'
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Apr 10, 2017 at 08:57 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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