cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to connect to a Company

Former Member
0 Kudos

 

Hi

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim oCompany As SAPbobsCOM.Company
        Dim lRetCode, lErrCode As Long
        Dim sErrMsg As String
        'Instantiate a Company object
        oCompany = New SAPBobsCOM.Company
        oCompany.Server = "localhost"
        oCompany.CompanyDB = "XYZ"
        oCompany.UserName = "manager"
        oCompany.Password = "manager"
        oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2008


        'Please note: Log on to SAP Business One with password

        lRetCode = oCompany.Connect()
        If oCompany.Connected = True Then
            MsgBox(oCompany.CompanyName)
        Else
            MsgBox("No Conneccted")

        End If

        'Check Return Code
        If lRetCode <> 0 Then
            oCompany.GetLastError(lErrCode, sErrMsg)
        End If
    End Sub
End Class

Thanks

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

You can try my code. I always do this. If you use this, your add-on will be flexible even your server credential has been changed.

    Private Sub ConnectToCompany()

        Try

            oCompany = SBO_Application.Company.GetDICompany

        Catch ex As Exception

            frmMaintenance.Freeze(False)

            'SAP_APP.SetMessage(ex)

        End Try

    End Sub

Former Member
0 Kudos

You provided the B1 credentials (user name and password) but not the SQL credentials (either the dbusername & dbpassword) or set the use trusted flag to Yes for Windows authentication.

Former Member
0 Kudos

Hi

   I am still unable to connect

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim oCompany As SAPbobsCOM.Company

Dim lRetCode, lErrCode As Long

Dim sErrMsg As String

'Instantiate a Company object

oCompany = New SAPbobsCOM.Company

oCompany.Server = "localhost"

oCompany.CompanyDB = "XYZ"

oCompany.UserName = "manager"

oCompany.Password = "business"

oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2008

oCompany.DbUserName = "sa"

oCompany.DbPassword = "sal"

lRetCode = oCompany.Connect()

If oCompany.Connected = True Then

MsgBox(oCompany.CompanyName)

End If

'Check Return Code

If lRetCode <> 0 Then

oCompany.GetLastError(lErrCode, sErrMsg)

End If

End Sub

End Class

Former Member
0 Kudos

Hi,

Your code will not work even you debug it whole day.

You my try my code.

And I don't think this code is correct (Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles) Have you read the SDK file for SAP Business One?

You can check some sample here.

C:\Program Files\SAP\SAP Business One SDK\Samples\COM UI\VB.NET


You should study first on how you catch the item event.

Public Class Form1

Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent

     Select Case pVal.Action_Success

                Case False

                Case True

               Call ConnectToCompany()

     End Select

End Sub

Function ConnectToCompany()  As Boolean

        Try

           Dim oCompany As SAPbobsCOM.Company

            oCompany = SBO_Application.Company.GetDICompany

        Catch ex As Exception

            frmMaintenance.Freeze(False)

            MsgBox(ex)

        End Try

    End Function

End Class