cancel
Showing results for 
Search instead for 
Did you mean: 

Failed to connect Company (-222)

Former Member
0 Kudos

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??

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

What is the value returned by the function ConnectToCompany ?

It will give u some -ve number.If u search that number in the help center u can fild solution in it.

Former Member
0 Kudos

returning

-222

Former Member
0 Kudos

The function must be returning a different value since -222 is not present in the error code list.

Former Member
0 Kudos

Sorry ,

Value of connectToCompanyReturn=-222

Former Member
0 Kudos

When Running connectToCompanyReturn=-222.

What might be the cause? Plz help.

Will you tell me that where can I find the error code list?

Former Member
0 Kudos

U can find the list of error codes in the SDK help center.

Vasu Natari.

Former Member
0 Kudos

Sibashish,

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

may be that helps.

regards,

Binita

Former Member
0 Kudos

Thanx for solving my problem.

No more reply required.

Edited by: Sibasish Sengupta on Sep 8, 2008 11:45 AM

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello...

I´m with the same problem, but the return code is -131

I try to find in the SDK Help Center, but i´m not found the errors list.

Can same one help me, please?

Tks