Connecting to SAP Business One Database Page 1 of 2
SAP Business One SDK 10.0
Connecting to SAP Business One Database
The Company object represents a company database of SAP Business One and is the highest
object in the object-hierarchy. This means that the Company object controls the access to SAP
Business One company database.
This procedure, followed by an example, is the first and mandatory code that your add-on must
start with.
To connect to SAP Business One database:
1. Set reference to the DI API COM object in your development environment:
In Visual Basic 6.0, choose Project > References and select SAP Business One DI API Version
2007.
In Visual Basic .NET, choose Project > Add Reference and from the COM tab, select SAP
Business One DI API Version 2007.
2. Initialize the company object: SAPbobsCOM.Company.
3. Set the mandatory properties for the connection to the database:
n Server name
n Company database name
n User name
n Password
n Logon language - you must ensure that external components use the same
character set as SAP Business One. The logon language is a member of the
enumeration class BoSuppLangs.
3. Use Windows Authentication for database server.
4. Log on to SAP Business One database.
5. Verify successful connection. The return code must be 0, otherwise check the error code.
Sample Code
' Define variables.
Dim vCmp As SAPbobsCOM.Company
Dim lRetCode, lErrCode As Long
Dim sErrMsg As String
'--------------------------------------------------------------------------------
-------
' Step 1
' Initialize the Company Object.
' You must create this first to enable connection to the company database.
Set vCmp = New SAPbobsCOM.Company
'--------------------------------------------------------------------------------
--------
' Step 2
' Set the mandatory connection properties.
vCmp.Server = "My_DB_Server" 'Name of the DB Server
vCmp.CompanyDB = "My_Company" 'Enter the name of your company
vCmp.UserName = "manager" 'Enter the B1 user name
vCmp.Password = "manager" 'Enter the B1 password
vCmp.Language = ln_English 'Enter the logon language
mk:@MSITStore:C:\Program%20Files%20(x86)\SAP\SAP%20Business%20One%2... 16/08/2023
Connecting to SAP Business One Database Page 2 of 2
'--------------------------------------------------------------------------------
---------
' Step 3
' Use Windows authentication for database server.
' True for NT server authentication,
' False for database server authentication.
vCmp.UseTrusted = True
'--------------------------------------------------------------------------------
---------
' Step 4
' Log on SAP Business One database.
lRetCode = vCmp.Connect
'--------------------------------------------------------------------------------
---------
' Step 5
' Check result code.
' To continue, the result code must be 0.
' Otherwise, check the error code and its related error message.
If lRetCode <> 0 Then
vCmp.GetLastError lErrCode, sErrMsg
End If
To close the connection:
Call the company object Disconnect() method:
vCmp.Disconnect
© Copyright 2020 SAP SE. All rights reserved.
mk:@MSITStore:C:\Program%20Files%20(x86)\SAP\SAP%20Business%20One%2... 16/08/2023