Skip to Content
0
Former Member
Oct 27, 2005 at 02:26 PM

Problem connecting an addon in 2004

16 Views

Hi

We have just upgraded a 6.5 site to 2004 and my addon doesn't seem to want to connect. I am using the standard dual logon code as I need the ui api and di api. I have included the addonIdentifier code but the connect to company routine is failing to connect to the company's database

Can anyone help pls ?

Regards Andy

'//**************************************************************************************************

Option Explicit

'//**********************************************************
'// This parameter will use us to manipulate the
'// SAP Business One Application
'//**********************************************************

Public WithEvents SBO_Application As SAPbouiCOM.Application

Public oFilters As SAPbouiCOM.EventFilters

Private oFilter As SAPbouiCOM.EventFilter


' Public oCompany As SAPbobsCOM.Company

Private Sub SetApplication()

'*******************************************************************
'// Use an SboGuiApi object to establish connection
'// with the SAP Business One application and return an
'// initialized appliction object
'*******************************************************************

    Dim SboGuiApi           As SAPbouiCOM.SboGuiApi
    Dim sConnectionString   As String
    
    Set SboGuiApi = New SAPbouiCOM.SboGuiApi
         
    '// by following the steps specified above, the following
    '// statment should be suficient for either development or run mode
    
    SboGuiApi.AddonIdentifier = "4CC8B8ACE0273A61489738C94047855DE8768CDD37F64D4F11E82759A542BD565D5B6E4150AF9B909FBE0FA944FA35C3B60AE771"

    
    sConnectionString = Command
    
    '// connect to a running SBO Application
    
    SboGuiApi.Connect sConnectionString
    
    '// get an initialized application object
    
    Set SBO_Application = SboGuiApi.GetApplication()
    
    ' ab test
    ' SBO_Application.MessageBox (SBO_Application.Company.Name)

End Sub

Public Sub Class_Initialize()

Dim lretcode As Long
Dim lErrCode As Long
Dim sErrMsg As String

'//*************************************************************
'// set SBO_Application with an initialized application object
'//*************************************************************
    SetApplication
    
        If Not SetConnectionContext = 0 Then
        SBO_Application.MessageBox "Failed setting a connection to DI API"
        End ' Terminating the add-on application
        End If

        If Not ConnectToCompany = 0 Then
        SBO_Application.MessageBox "Failed connecting to the company's Data Base"
        End ' Terminating the add-on application
    End If
    
'---- connect to another company
' 
Set oCompany2 = New SAPbobsCOM.Company
oCompany2.Server = "UK"
oCompany2.Language = ln_English
oCompany2.UseTrusted = False

oCompany2.CompanyDB = "timerep"
oCompany2.username = "manager"
oCompany2.Password = "fred"

lretcode = oCompany2.Connect
If lretcode = 0 Then
    ' SBO_Application.MessageBox "login ok"
Else
    ' SBO_Application.MessageBox "login failed"
    oCompany2.GetLastError lErrCode, sErrMsg
    MsgBox sErrMsg
 End If
    
    
'//*************************************************************
'// add the menu items
'//*************************************************************
    
    AddMenuItems
    
    '//*************************************************************
    '// set SBO_Application with an initialized EventFilters object
    '//*************************************************************
    
    SetFilters
    
End Sub



Private Sub SBO_Application_AppEvent(ByVal EventType As SAPbouiCOM.BoAppEventTypes)
    
    Select Case EventType
    
    
        Case aet_ServerTerminition:
            End
            
        Case aet_ShutDown:
             
             '// Take care of terminating your AddOn application
                
               ' SBO_Application.MessageBox ("A Shut Down Event has been caught" & _
               '     vbNewLine & "Terminating 'Label Print' Add On...")
            
            End
    
    End Select

End Sub

Private Function SetConnectionContext() As Long

    Dim sCookie As String
    Dim sConnectionContext As String
    Dim lretcode As Long
        
    '// First initialize the Company object:
    
    Set oCompany = New SAPbobsCOM.Company
        
    '// Acquire the connection context cookie from the DI API:
    sCookie = oCompany.GetContextCookie

    '// Retrieve the connection context string from the UI API using the
    '// acquired cookie:
    sConnectionContext = SBO_Application.Company.GetConnectionContext(sCookie)
    
    '// Set the connection context information to the DI API:
    SetConnectionContext = oCompany.SetSboLoginContext(sConnectionContext)
    
End Function


Private Function ConnectToCompany() As Long

    '// Establish the connection to the Company database:
    ConnectToCompany = oCompany.Connect

End Function