cancel
Showing results for 
Search instead for 
Did you mean: 

Connect company in SAP 8.81

Former Member
0 Kudos

I am using SAP 8.81.I am using the following code to connect to company -


Public Function ConnectToCompany()
        Dim strCookie As String
        Dim strConnection As String

        Try
            MessageBox.Show("Start ConnectToCompany")
            *objCompany = New SAPbobsCOM.Company*
            MessageBox.Show(1)
            strCookie = objCompany.GetContextCookie
            MessageBox.Show(2)
            strConnection = SBO_Application.Company.GetConnectionContext(strCookie)
            MessageBox.Show(3)
            objCompany.DbServerType = BoDataServerTypes.dst_MSSQL2008
            MessageBox.Show(4)
            objCompany.SetSboLoginContext(strConnection)
            MessageBox.Show(5)
            objCompany.Connect()
            MessageBox.Show(6)
            If objCompany.GetLastErrorDescription.Length > 0 Then
                SBO_Application.MessageBox(objCompany.GetLastErrorDescription)
            Else
                If SBO_Application.Desktop.Title.Contains("2005") Then
                    strFormType = "390"
                    strControl = "141"
                    dblCount = 117
                    strSeries = "JV/R"
                ElseIf SBO_Application.Desktop.Title.Contains("8.8") Then
                    MessageBox.Show(7)
                    strFormType = "392"
                    strControl = "137"
                    dblCount = 140
                    strSeries = "JV/R"
                End If
                MessageBox.Show(8)
                GetAuthentication()
                MessageBox.Show(9)
            End If
            MessageBox.Show("End ConnectToCompany")
        Catch ex As Exception
            SBO_Application.MessageBox("Tour Reporter:ConnectToCompany()=" & ex.Message)
        End Try
    End Function

I have used message boxes to tracking the flow of the code.The message "Start ConnectToCompany " fires.After this message does not appear. The execution stops at the statement,

objCompany = New SAPbobsCOM.Company

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Go your code window menu>projectApplicationpropertiesdebug>

give this one....

0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056

Try this code,

Private Sub SetApplication()

Try

Dim SboGuiApi As SAPbouiCOM.SboGuiApi

Dim sConnectionString As String

SboGuiApi = New SAPbouiCOM.SboGuiApi

sConnectionString = Environment.GetCommandLineArgs.GetValue(1)

SboGuiApi.Connect(sConnectionString)

SBO_Application = SboGuiApi.GetApplication()

Catch ex As Exception

SBO_Application.MessageBox(ex.Message)

End Try

End Sub

Private Function SetConnectionContext() As Integer

Dim sCookie As String

Dim sConnectionContext As String

Dim lRetCode As Integer

Try

ocompany = New SAPbobsCOM.Company

sCookie = ocompany.GetContextCookie

sConnectionContext = SBO_Application.Company.GetConnectionContext(sCookie)

If ocompany.Connected = True Then

ocompany.Disconnect()

End If

SetConnectionContext = ocompany.SetSboLoginContext(sConnectionContext)

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

End Function

Private Function ConnectToCompany() As Integer

Try

ConnectToCompany = ocompany.Connect

Catch ex As Exception

SBO_Application.MessageBox(ex.Message)

End Try

End Function

Private Sub Class_Init()

Try

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

SBO_Application.MessageBox("Connected")

Catch ex As Exception

SBO_Application.MessageBox(ex.Message)

End Try

End Sub

Regards,

Siva

Former Member
0 Kudos

Sivabalan,

I have already tried,

ocompany = New SAPbobsCOM.Company

And it is not working.

Former Member
0 Kudos

HI,

1.Restart system.

2.Delete Temp files.

3.Try this code,

OCompany = New SAPbobsCOM.Company

OCompany.UseTrusted = False

OCompany.Server = ServerName

OCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2008

OCompany.language = SAPbobsCOM.BoSuppLangs.ln_English

OCompany.DbUserName = "xx"

OCompany.DbPassword = "xxxxx"

OCompany.CompanyDB = CompanyDB

OCompany.UserName = "xxx"

OCompany.Password = "xxxx"

lRetCode = OCompany.Connect

If lRetCode <> 0 Then

OCompany.GetLastError(lErrCode, sErrMsg)

MsgBox(sErrMsg)

End If

Regards,

Siva

Former Member
0 Kudos

This is taken from the SDK helpfile (it should have been SBO_Application.Company.GetDICompany()):

SboGuiApi = New SAPbouiCOM.SboGuiApi
'// Connect to a running SBO Application
If connectionString = "" Then
    If Environment.GetCommandLineArgs().Length = 1 Then
        sConnectionString = "0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056"
    Else
        sConnectionString = Environment.GetCommandLineArgs.GetValue(1)
    End If
Else
    '//Connection string was filled before
End If

SboGuiApi.Connect(sConnectionString)
SBO_Application = SboGuiApi.GetApplication()

'// Get DI company via multiple addon (via UI)
Dim oCompany As SAPbobsCOM.Company
oCompany = SBO_Application.Company.GetDICompany()

'// No need to connect

For me, your code is missing Dim oCompany AS SapbobsCOM.Company.

Former Member
0 Kudos

I tried your code but it gave me error as

Internal error (-2147221164) occurred [131-183] - Class not registered

This error occured for the statement,

objCompany = SBO_Application.Company.GetDICompany()

Former Member
0 Kudos

Hi,

First try sample code its connecting or not,

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

Regards,

Siva

Former Member
0 Kudos

I have tried alomost every code and none of the code is working for SAP 8.81.

Former Member
0 Kudos

Did you try this:

Go to start->Run-%temp%

Delete the SM_OBS_DLL folder

Uninstall DI API

Restart machine

Reinstall DI API

What DI references do you have in your project?

Former Member
0 Kudos

njmog1,

I have re-installed DI API as per your instructions.Now I can find SAP Business One UI API Version 8.81 in the references but I can not find SAP Business One DI API Version 8.81.How do I add the reference of SAP Business One DI API Version 8.81 ?

Answers (1)

Answers (1)

Former Member
0 Kudos

First of all, in 8.81 you don't need to bother with cookies and connection context.

Just use:

oCompany = SBO_Application.GetDICompany()

But that obviously doesn't solve your issue. What happens when you debug it? Instead of running it where each message box pops up, step through the code using F10.

One thing I don't see is your company object declaration?

Dim oCompany AS SAPbobsCOM.Company

If you already have that, then next is to clean your DI.

Go to start->Run-%temp%

Delete the SM_OBS_DLL folder

Uninstall DI API

Restart machine

Reinstall DI API

Then try to run your project in debug mode and let us know what happens.

Former Member
0 Kudos

njmog1 ,

I tried your code but it did not worked.Can you please give me the latest code of connecting to company ?