cancel
Showing results for 
Search instead for 
Did you mean: 

How to assign value to oApplication object

ramco1917
Participant
0 Kudos
72

Hi

  I have below code . How to assign value to oApplication object

Hi

  I have below code i am getting error - Object reference not set to an instance of the Object.

oApplication.MessageBox("Sap B1 Connected");

SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
oCompany.Server = "10.0.1.28:30013";
oCompany.DbServerType = BoDataServerTypes.dst_HANADB;
oCompany.CompanyDB = "LIVE";
oCompany.UserName = "manager";
oCompany.Password = "123";
oCompany.language = BoSuppLangs.ln_English;
oCompany.UseTrusted = true;

int connectionResult = oCompany.Connect();
if (connectionResult != 0)
{
    throw new Exception("Error connecting to SAP Business One: " + oCompany.GetLastErrorDescription());
}

oApplication.MessageBox("Sap B1 Connected");
C#
Copy

Thanks

Thank

Accepted Solutions (0)

Answers (1)

Answers (1)

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi ramco1917,

You need to make sure that your UI API connection is successful before using oApplication. UI API connection can be made as below:

 

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 ); 

 

If you want to display only the MessageBox, you can use some other option. For example:

MessageBox.Show("Connected!");

Hope it helps!

Kind regards,

ANKIT CHAUHAN

SAP Business One Support

ramco1917
Participant
0 Kudos

Hi Ankit

If I make connection as per my code then also it is to be done same way.

Only Command line arguments is the way.

Thanks