Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Failed to connect Company (-222)

Trying to connect DI from UI API.

private SAPbobsCOM.Company oCompany; 
        private SAPbouiCOM.Application SBO_Application; 
        
        // '''''''''''''''''
        //  Connect to SBO '
        // '''''''''''''''''
        private void SetApplication() { 
            SAPbouiCOM.SboGuiApi SboGuiApi = null; 
            string sConnectionString = null; 
            
            SboGuiApi = new SAPbouiCOM.SboGuiApi(); 
            
            sConnectionString = System.Convert.ToString( Environment.GetCommandLineArgs().GetValue( 1 ) ); 
            SboGuiApi.Connect( sConnectionString ); 
            SBO_Application = SboGuiApi.GetApplication( -1 ); 
            
        } 
        
        
        // '''''''''''''''''''''''''''''''''
        //  Connect with connection string '
        // '''''''''''''''''''''''''''''''''
        private int SetConnectionContext() { 
            int setConnectionContextReturn = 0;
            
            string sCookie = null; 
            string sConnectionContext = null; 
            int lRetCode = 0; 
            
            oCompany = new SAPbobsCOM.Company(); 
            
            sCookie = oCompany.GetContextCookie(); 
            sConnectionContext = SBO_Application.Company.GetConnectionContext( sCookie ); 
            
            if ( oCompany.Connected == true ) { 
                oCompany.Disconnect(); 
            } 
            setConnectionContextReturn = oCompany.SetSboLoginContext( sConnectionContext ); 
            
            return setConnectionContextReturn;
        } 
        
        
        // '''''''''''''''''
        //  Connect to SBO '
        // '''''''''''''''''
        private int ConnectToCompany() { 
            int connectToCompanyReturn = 0;
            
            // Establish the connection to the company database.
            connectToCompanyReturn = oCompany.Connect(); 
            
            return connectToCompanyReturn;
        }
// '''''''''''''''''
        //  Init the Class '
        // '''''''''''''''''
        public Test() : base() { 
            
            SetApplication(); 
            if ( !( SetConnectionContext() == 0 ) ) { 
                SBO_Application.MessageBox( "Failed setting a connection to DI API", 1, "Ok", "", "" ); 
                System.Environment.Exit( 0 ); //  Terminating the Add-On Application
            } 
            if ( !( ConnectToCompany() == 0 ) ) { 
                SBO_Application.MessageBox( "Failed connecting to the company's Data Base", 1, "Ok", "", "" ); 
                Application.Exit(); //  Terminating the Add-On Application
            } 
            
            SBO_Application.MessageBox( "DI Connected To: " + oCompany.CompanyName, 1, "Ok", "", "" ); 
            // events handled by SBO_Application_ItemEvent
			bool tmpB = false;

			SBO_Application.ItemEvent += new SAPbouiCOM._IApplicationEvents_ItemEventEventHandler( SBO_Application_ItemEvent ); 
 
        } 

But Getting error "Failed to connect company" . Why??

replied

Sibashish,

-222 is perhaps posting period problem, try creating a new valid period and set it as default.

may be that helps.

regards,

Binita

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question