Showing results for 
Search instead for 
Did you mean: 

DI: User name and password for DI connection(6.2)

Former Member
0 Kudos


I've just write Add-On for version 6.2 that uses UI and DI. Now, I've got a problem to get user name and password in order to connect with database via DI. I know this problem was solved in 6.5 (single sign-on).Does anybody know a simple(or not) way to do this in 6.2?

Thank you

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Lutz

This is very simple - to open form and ask for user name and password. But it's a last thing I want to do, because it's not convinient way for user. What do you think about storing that data in the registry(password in encripted format)?

Thank you

Former Member
0 Kudos

Hi Mark,

I did not mean opening a form asking the user for the values necessary for a connection. Actually, the UIAPI does exactly that and there should be no need to do that twice.

The point is reading the data out of the "ChooseCompany" form where it already is. (Read the username out of the edittext control in the form etc.

It does work, although all you can read out here is the company name, not the company database name.

The UIAPI <i>knows</i> which database it is currently connected to. There should be no need to store the info in the database a second time (it is already stored in sql server by SAP anyway). I find the solution a valuable workaround. Since an upgrade to 6.5 is in sight, I do not feel the need to invest time in another solution which gets obsolete with the upgrade.

HTH, Lutz Morrien

Former Member
0 Kudos


I can post the main code in if you want it.

Lutz Morrien

Former Member
0 Kudos

Hi Lutz

It's very interesting . If you can post this code it will help me. Thank you very much.

Former Member
0 Kudos

Hi Mark,

hope this helps. This workaround was originally created by Rez Hotz-Pohlmann.

Lutz Morrien

Private Function ConnectToDIAPI() As Boolean

Dim diRstCompany As SAPbobsCOM.Recordset

Dim uiFrm As SAPbouiCOM.Form

Dim CurrentServer As String

Dim CurrentDatabase As String

Dim CurrentUserName As String

Dim CurrentPassword As String

Dim CurrentLanguage As SAPbobsCOM.BoSuppLangs


'Create company object

SBO_Company = New SAPbobsCOM.Company

'open SBO form "ChooseCompany", which contains all necessary Information


'open form ChooseCompany

uiFrm = SBO_Application.Forms.GetFormByTypeAndCount(uiFormTypes.ChooseCompany, 1)

'minimize SBO form "ChooseCompany to prevent user entries

uiFrm.State = SAPbouiCOM.BoFormStateEnum.fs_Minimized

'readout necessary information

CurrentServer = uiFrm.Items.Item("23").Specific.String()

CurrentUserName = uiFrm.Items.Item("19").Specific.String

CurrentPassword = uiFrm.Items.Item("20").Specific.String


'get companylist from idenfified server

SBO_Company.Server = CurrentServer

'ATTENTION: GetCompanyList takes approximately 10 seconds to complete

diRstCompany = SBO_Company.GetCompanyList

'find currently chosen company in companylist

Do Until diRstCompany.EoF

If CStr(diRstCompany.Fields.Item("cmpName").Value) = SBO_Application.Company.Name Then

Exit Do



End If


If diRstCompany.EoF Then

'company not found!

' This should not happen,

'since the SBO client should always be connected with a company

Throw New Exception(SBO_Application.Company.Name & " not found")


'set identified database

CurrentDatabase = CStr(diRstCompany.Fields.Item("dbName").Value)

'finally, connect to company

With SBO_Company

.Server = CurrentServer

.CompanyDB = CurrentDatabase

.UserName = CurrentUserName

.Password = CurrentPassword

.UseTrusted = False

.language = SBO_Application.Language

End With


'catch error if there is any

Dim ErrCode As Integer

Dim ErrMessage As String

If Not SBO_Company Is Nothing Then

SBO_Company.GetLastError(ErrCode, ErrMessage)

'if there really is an error

'then show it in SBO

If ErrCode <> 0 Then

SBO_Application.MessageBox("Fehler Nr.: " & ErrMessage & _

vbCrLf & ErrMessage)

Return False


SBO_Application.SetStatusBarMessage("DIAPI Connected to " & CurrentDatabase, SAPbouiCOM.BoMessageTime.bmt_Long, False)

Return True

End If

End If

End If

Catch excE As Exception


End Try

End Function

Former Member
0 Kudos

Hi Lutz

I've tried and it works! What a smart solution!

Thank you very mach!

Former Member
0 Kudos

This is very smart solution. Unfortunately there is a problem with databases with the same “company name” (e.g. same company – different year). I tried to retrieve information directly from matrix (from selected row) but it doesn’t work.

MyMatrix = ChooseFrm.Items(“4”).Specific

… and I get “Invalid Item” error. Any ideas?

Former Member
0 Kudos

Hi Szymon,

maybe renaming the company is an option.

Something like MyCompanyName2003 and MyCompanyName2004

After all, they do not contain the same data.

This seems like the simplest solution, without having to do any extra coding. HTH Lutz Morrien

MyMatrix = ChooseFrm.Items(“4”).Specific should work in order to get the Matrix object.

Former Member
0 Kudos

Hi Mark,

simlest way is opening up the "choose company" form and reading out the data you need. You can get everything but the database name out of this form. Check my earlier postings. I have answered on this issue before. There might be some VB sample code available in this forum. If not, just ask for it.

It is a little clumsy as a solution, but it works.

HTH Lutz Morrien