cancel
Showing results for 
Search instead for 
Did you mean: 

SingleSignOn error

Former Member
0 Kudos

I am getting a weird error which occurs only when using UK Database but not other databases.

Error is as follows:

"Object reference not set to an instance of an object"

Below is the error line in <u><b>BOLD</b></u>

Private Sub SingleSignOn()

Try

oCompany = New SAPbobsCOM.Company

sCookie = oCompany.GetContextCookie

sConnectionContext = SBO_Application.Company.GetConnectionContext(sCookie) 'GET COOKIE FROM UI

If oCompany.Connected = True Then

oCompany.Disconnect()

End If

sConnectionContext = oCompany.SetSboLoginContext(sConnectionContext) 'SET COOKIE TO DI

<b><u>lRetCode = oCompany.Connect</u></b> 'line error

If oCompany.Connected = True Then

'SBO_Application.MessageBox("Connected via SingleSignOn")

End If

Catch ex As Exception

SBO_Application.MessageBox(ex.Message)

MsgBox(ex.Message + vbCrLf + ex.StackTrace, MsgBoxStyle.Critical, "SBO BAPI ERROR")

End Try

End Sub

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member184566
Active Contributor
0 Kudos

Okay, you win

Former Member
0 Kudos

I manage to find out the problem.

I have manually inserted a field with non-existance table into CUFD.

former_member184566
Active Contributor
0 Kudos

But i do agree with you if his doing a DI Connect only.

By the way, hows things going?

Former Member
0 Kudos

Hi Louis,

Things are going great! Very busy though, thanks!

You also have that line you are referring to in your code. Look at the procedure ConnectToCompany:

    Private Function ConnectToCompany() As Integer
        '// Establish the connection to the company database.
        ConnectToCompany = oCompany.Connect
    End Function

Adele

former_member184566
Active Contributor
0 Kudos

Hi Adele,

Please explain why you need this. When we say single sign on we mean GUI and DI. That's how i understand it. I assumed he is doing a connection to both as his function is called single sign on.Then if you look at the SAP examples they don't use that. Here is there example. Please elaborate, i need to learn from the master.

#Region "Single Sign On"

Private Sub SetApplication()

AddStarted = False

RedFlag = False

'*******************************************************************

'// Use an SboGuiApi object to establish connection

'// with the SAP Business One application and return an

'// initialized application object

'*******************************************************************

Dim SboGuiApi As SAPbouiCOM.SboGuiApi

Dim sConnectionString As String

SboGuiApi = New SAPbouiCOM.SboGuiApi

'// by following the steps specified above, the following

'// statement should be sufficient for either development or run mode

sConnectionString = Environment.GetCommandLineArgs.GetValue(1)

'// connect to a running SBO Application

SboGuiApi.Connect(sConnectionString)

'// get an initialized application object

SBO_Application = SboGuiApi.GetApplication()

End Sub

Private Function SetConnectionContext() As Integer

Dim sCookie As String

Dim sConnectionContext As String

Dim lRetCode As Integer

Try

'// First 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 = SBO_Application.Company.GetConnectionContext(sCookie)

'// before setting the SBO Login Context make sure the company is not

'// connected

If oCompany.Connected = True Then

oCompany.Disconnect()

End If

'// Set the connection context information to the DI API.

SetConnectionContext = oCompany.SetSboLoginContext(sConnectionContext)

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

End Function

Private Function ConnectToCompany() As Integer

'// Establish the connection to the company database.

ConnectToCompany = oCompany.Connect

End Function

Private Sub Class_Init()

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

'// set SBO_Application with an initialized application object

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

SetApplication()

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

'// Set The Connection Context

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

If Not SetConnectionContext() = 0 Then

SBO_Application.MessageBox("Failed setting a connection to DI API")

End ' Terminating the Add-On Application

End If

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

'// Connect To The Company Data Base

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

If Not ConnectToCompany() = 0 Then

SBO_Application.MessageBox("Failed connecting to the company's Data Base")

End ' Terminating the Add-On Application

End If

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

'// send an "hello world" message

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

SBO_Application.MessageBox("DI Connected To: " & oCompany.CompanyName & vbNewLine & "Add-on is loaded")

End Sub

#End Region

former_member184566
Active Contributor
0 Kudos

Yes, strange. But why even have that line? It's not necassery for the connection. I don't ever use or have that line?

Former Member
0 Kudos

Hi,

You must have that line to connect to the DI. Your code looks fine to me. Are you connected to the SBO_Application GUI? Maybe do a SBO_Application.MessageBox("whatever") to see if you are connected to the UI.

Hope it helps,

Adele