📚 SAP Business One SDK Help

Disconnect method
See Also

Description

The following example shows how to disconnect the company object.
Private Sub cmdTest_Click()
   On Error GoTo ErrorHandler
   Dim vCompany As SAPbobsCOM.Company

   'create company object
   Set vCompany = New SAPbobsCOM.Company

   'set paras for connection
   vCompany.CompanyDB = "SBODemo_US"
   vCompany.Password = "manager"
   vCompany.UserName = "manager"
   vCompany.Server = "(local)"

   'connect to database server
   If (0 <> vCompany.Connect()) Then
      MsgBox "Failed to connect"
      Exit Sub
   End If

   'do it now


   'Check Error
   Dim nErr As Long
   Dim errMsg As String

   Call vCompany.GetLastError(nErr, errMsg)
   If (0 <> nErr) Then
       MsgBox ("Found error:" + errMsg)
   End If

   'disconnect the company object, and release resource
   Call vCompany.Disconnect
   Set vCompany = Nothing
   Exit Sub
ErrorHandler:
   MsgBox ("Exception:" + Err.Description)
End Sub