Skip to Content
0
Former Member
Jul 20, 2005 at 06:19 PM

Mod shows "Failed" in Addon Manager, but it works... what is wrong?

23 Views

I have two addons that are installed and working; but, the Addon Manager says they have Failed connecting. Also, the Addons take ~15 seconds to connect, which seems a bit long to me. I am including all my connection code.


Imports Microsoft.VisualBasic
Imports Microsoft.VisualBasic.VariantType
Imports Microsoft.VisualBasic.Constants
Imports Microsoft.VisualBasic.Interaction
Imports System.Diagnostics
Imports System.Collections
Imports System.Windows
Imports System.Windows.Forms.Application
Imports SAPbouiCOM.BoTextStyle
Imports SAPbouiCOM.BoFormMode
Imports SAPbouiCOM.BoEventTypes
Imports SAPbobsCOM.BoObjectTypes
Imports SAPbouiCOM.BoFormItemTypes
Imports SAPbouiCOM.BoDataType

Friend Class ABYMods

    Private WithEvents oApplication As SAPbouiCOM.Application
    Private WithEvents oCompany As SAPbobsCOM.Company

#Region "Setup"

    Public Sub New()

        MyBase.New()

        SetApplication()

        If Not SetConnectionContext() = 0 Then
            MsgBox("Failed setting a connection to DI API.")
            'End  ' Terminating the Add-On Application
            Exit Sub  ' Terminating the Add-On Application
        End If

        If ConnectToCompany() = False Then
            MsgBox("Failed connecting to company's database.")
            'End  ' Terminating the Add-On Application
            Exit Sub  ' Terminating the Add-On Application
        End If

    End Sub

    Public Shared Sub Main()

        Dim oABYMods As ABYMods
        oABYMods = New ABYMods
        Application.Run()

    End Sub

    Private Sub SetApplication()

        Dim SboGuiApi As SAPbouiCOM.SboGuiApi
        Dim sConnectionString As String

        Try

            SboGuiApi = New SAPbouiCOM.SboGuiApi

            sConnectionString = Environment.GetCommandLineArgs.GetValue(1)
            'sConnectionString = "0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056"

            '// GetAddOnIdentifier() is a function to return a string with the 
            '// appropriate identifier for the Addon.
            '// This will be required after 2005!  (We currently return a blank string.)
            SboGuiApi.AddonIdentifier = GetAddOnIdentifier()

            '// connect to a running SBO Application
            SboGuiApi.Connect(sConnectionString)

            '// get an initialized application object
            oApplication = SboGuiApi.GetApplication()

            'SetFilters()

        Catch
            MessageBox.Show("No SAP Business One Application was found.")
        End Try

    End Sub

    Private Function GetAddOnIdentifier() As String
        ' We will need to set this up before 2006 for our Addons to be recognized by the License Manager
        GetAddOnIdentifier = ""
    End Function

    Private Function SetConnectionContext() As Integer

        Dim sCookie As String
        Dim sConnectionContext As String

        Try
            ' Initialize the company object
            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 = oApplication.Company.GetConnectionContext(sCookie)

            If oCompany.Connected Then
                oCompany.Disconnect()
            End If

            ' Set the connection context information to the DI API
            SetConnectionContext = oCompany.SetSboLoginContext(sConnectionContext)

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Function

    Private Function ConnectToCompany() As Boolean
        Dim counter As Integer
        counter = 0
        Try
            Do While oCompany.Connected = False
                If oCompany.Connect <> 0 Then
                    counter = counter + 1
                    If counter > 10 Then
                        ConnectToCompany = False
                        Exit Do
                    End If
                    ' When using multiple AddOns, problems with each trying to connect at the same time have been found.
                    ' So, we try multiple times and wait 50ms more between each iteration.
                    Call System.Threading.Thread.Sleep(counter * 50)
                Else
                    ConnectToCompany = True
                End If
            Loop
        Catch ex As Exception
            MsgBox("oCompany.Connect failed in ConnectToCompany()")
        End Try
    End Function

#End Region