on 07-19-2011 9:24 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
102 | |
12 | |
11 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.