Establishing 2 Connections with DI API (Version FP2402 HF1) at the same time is working properly. Disconnecting each Connections is also working correct, but when you set the second Company Object to Nothing, then the App (e.g. Excel) crashes.
With older versions of DI API (e.g. 9.3) it was not a problem to have more than one connection working properly.
Does anyone have the same problem with FP2402 or with other versions?
Or maybe someone already has a solution for this?
If anyone want to try, then here some VBA code to adapt easily within e.g. Excel, Word or Access.
Best Regards
Klaus
Private Sub SAP_DIAPI_Connect_Disconnect_TEST()
'Code more or less from SDK Documentation REFDI.chm
Dim ErrorCode As Long, ErrorMessage As String
Dim pServer As String, pCompanyDB1 As String, pCompanyDB2 As String, pSBO_User As String, pSBO_Passwort As String
Dim pUseTrusted As Boolean, pDBServerType As Long
Dim oCompany1 As Object, oCompany2 As Object
pServer = "b1server": pUseTrusted = False: pDBServerType = 15
pSBO_User = "manager"
pSBO_Passwort = "1234"
pCompanyDB1 = "companyDB1": pCompanyDB2 = "companyDB2"
'***********************************************************
'CONNECTION 1 TO DB1
'***********************************************************
Set oCompany1 = CreateObject("SAPbobsCOM.Company")
oCompany1.UseTrusted = pUseTrusted
oCompany1.DbServerType = pDBServerType
oCompany1.Server = pServer
oCompany1.SLDServer = "https://" & pServer & ":40000"
oCompany1.CompanyDB = pCompanyDB1
oCompany1.UserName = pSBO_User
oCompany1.Password = pSBO_Passwort
ErrorCode = oCompany1.Connect
If ErrorCode <> 0 Then
oCompany1.GetLastError ErrorCode, ErrorMessage
ErrorMessage = oCompany1.GetLastErrorDescription()
Debug.Print pCompanyDB1 & vbTab & "-> Not Connected : " & ErrorCode & " " & ErrorMessage
Else
Debug.Print pCompanyDB1 & vbTab & "-> Connected"
End If
'***********************************************************
'CONNECTION 2 TO DB2
'***********************************************************
Set oCompany2 = CreateObject("SAPbobsCOM.Company")
oCompany2.UseTrusted = pUseTrusted
oCompany2.DbServerType = pDBServerType
oCompany2.Server = pServer
oCompany2.SLDServer = "https://" & pServer & ":40000"
oCompany2.CompanyDB = pCompanyDB2
oCompany2.UserName = pSBO_User
oCompany2.Password = pSBO_Passwort
ErrorCode = oCompany2.Connect
If ErrorCode <> 0 Then
oCompany2.GetLastError ErrorCode, ErrorMessage
ErrorMessage = oCompany2.GetLastErrorDescription()
Debug.Print pCompanyDB2 & vbTab & "-> Not Connected : " & ErrorCode & " " & ErrorMessage
Else
Debug.Print pCompanyDB2 & vbTab & "-> Connected"
End If
Debug.Assert False
'***********************************************************
'START DISCONNECTING
'***********************************************************
If Not oCompany1 Is Nothing Then
oCompany1.Disconnect
Set oCompany1 = Nothing
End If
If Not oCompany2 Is Nothing Then
oCompany2.Disconnect
Set oCompany2 = Nothing '<-- here Excel crashes
End If
End Sub
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.