cancel
Showing results for 
Search instead for 
Did you mean: 

Connection To Database

ramco1917
Participant
101

Hi

 One way to connect to Database is below . One is using Command Line. Which is the best method .

company.Server = ConfigurationManager.AppSettings["server"].ToString();
company.CompanyDB = ConfigurationManager.AppSettings["companydb"].ToString();
company.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012;
company.DbUserName = ConfigurationManager.AppSettings["dbuser"].ToString();
company.DbPassword = ConfigurationManager.AppSettings["dbpassword"].ToString();
company.UserName = ConfigurationManager.AppSettings["user"].ToString();
company.Password = ConfigurationManager.AppSettings["password"].ToString();
company.language = SAPbobsCOM.BoSuppLangs.ln_English_Gb;
company.UseTrusted = false;
company.LicenseServer = ConfigurationManager.AppSettings["licenseServer"].ToString();

connectionResult = company.Connect();

Thanks

View Entire Topic
ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert

Hi ramco1917,

When working with add-ons in SAP Business One, there can be 3 types of connection:

  • UI API connection: When you need to simulate the UI API behaviour.
  • DI API connection: When you need to automate the Business Processes without simulating UI API behaviour.
  • UI-DI connection: When you need to simulate the UI API behaviour, also need to automate the processes.

The sample you have shared, is a DI API connection. The connect which you make via Command Line, is generally a UI API connection.

Kind regards,

ANKIT CHAUHAN

SAP Business One Support

ramco1917
Participant
0 Kudos
Hi Ankit , Thanks a lot. Can u please provide me one example to make Ui-Di connection using c#
ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi ramco1917,

Refer to the following sample code:

1. Connect to the UI API as in a regular UI API add-on (SAP Business One must be running):

Dim SboGuiApi As SAPbouiCOM.SboGuiApi

Dim sConnectionString As String

SboGuiApi = New SAPbouiCOM.SboGuiApi

'// connect to a running SBO Application

If connectionString = "" Then

   If Environment.GetCommandLineArgs().Length = 1 Then

sConnectionString = "0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056"

   Else

     sConnectionString = Environment.GetCommandLineArgs.GetValue(1)

   End If

   Else

     ''connection string was filled before

End If

SboGuiApi.Connect(sConnectionString)

'// get an initialized application object

SBO_Application = SboGuiApi.GetApplication()

2. Connect to DI API using Company.GetDICompany:

Dim oCompany As SAPbobsCOM.Company

'//get DI company (via UI)

oCompany = SBO_Application.Company.GetDICompany()

---------------------------------------------------------

'// there is no need to call DI API Company.Connect method

Kind regards,

ANKIT CHAUHAN

SAP Business One Support