on 07-08-2010 5:32 AM
Hello All,
I am trying to write a Windows Service for adding a Sales Order .
This windows service will be doing this purpose of Sales Order after a certain time period say 15 seconds .
Data for that order will come from a UDT .
It will be a continuos process untill each sales order are created.
I have written the code for this windows service but while deploying the service and running it throws an
error "Service on Local computer started & stopped .Some services stop automatically if they have no work to do "
and the connection is not established with the SAP and the Sales Order code is not runnning .
For reference here is the code which i have written :-
Public oCompany As SAPbobsCOM.Company
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
Timer1.Enabled = True
oCompany = New SAPbobsCOM.Company
oCompany.Server = oCompany.Server ' Init Connection Properties
oCompany.CompanyDB = "Test_Db"
oCompany.UserName = "manager"
oCompany.Password = "manager"
oCompany.DBUserName="sa"
oCompany.DBPassword="sa"
oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2005
oCompany.UseTrusted = True
oCompany.Connect()
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
Timer1.Enabled = False
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Try
Timer1.Enabled = False
'==== Declare Variables ===='
Dim lRetCode, lErrCode As Integer
Dim sErrMsg As String = 1
Dim LineId As Integer = 0
Dim UnitPrice As Double = 0
Dim Quantity As Double = 0, Discount As Double = 0
Dim ItemCode As String
Dim Ammend_Num As Integer = 0
Dim Ammend_Date As String = ""
ocompany.StartTransaction()
'==== Declare The Purchase Order Object For Automatic Creation ===='
Dim oOrder As SAPbobsCOM.Documents = ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)
oOrder.CardCode = "A0001"
oOrder.Lines.ItemCode = "58"
oOrder.Lines.Quantity = 0.1
oOrder.Lines.WarehouseCode = "02"
oOrder.Lines.BatchNumbers.BatchNumber = "TH"
oOrder.Lines.BatchNumbers.Quantity = 2
'==== Update The Purchase Order With Current Data ====='
lRetCode = oOrder.Add
'=== Check For Error if any ===='
If lRetCode 0 Then
ocompany.GetLastError(lErrCode, sErrMsg)
If (lErrCode -4006) Then
MsgBox(sErrMsg)
ocompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
End If
End If
ocompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
Catch ex As Exception
MsgBox(ex.Message)
ocompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
End Try
Timer1.Enabled = True
End Sub
Thanks & Regards
Amit
Hi,
Two suggestions: I would not use the usetrusted options as you already have SA password. And I would use the license server option:
oCompany = New SAPbobsCOM.Company
oCompany.Server = My.Settings.Server
oCompany.CompanyDB = "SERVERNAME"
oCompany.UserName = "sa"
oCompany.Password = "sa"
oCompany.language = SAPbobsCOM.BoSuppLangs.ln_English
oCompany.DbUserName = manager
oCompany.DbPassword = manager
oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2005
oCompany.LicenseServer = "SERVERNAME:30000"
lRetCode = oCompany.Connect()
This way it should work. It might be a good idea to log the lRetcode to a file or windows events, so you can see what is happening while connecting.
Kind regards,
Winfried Tiemessen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Amit,
2 things,
1st The company dbname is missing
ocompany.DBName ="YOURCOMPANYDATABASENAME"
2nd You should use usetrusted = false because the localsystem account access to sql server is not trusted (a), or you can use trusted connection if you run the service as administrator not localsystema account (b)
so (b) Non trusted connection procide your username and password
oCompany.Server = oCompany.Server ' Init Connection Properties
oCompany.CompanyDB = "Test_Db"
oCompany.UserName = "manager"
oCompany.Password = "manager"
oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2005
oCompany.UseTrusted = False
oCompany.DBUserName="sa"
oCompany.DBPassword="sa"
ocompany.CompanyDB = "YOURCOMPANYNAME"
or
(b) Trusted connection and service running as Administrator
oCompany.Server = oCompany.Server ' Init Connection Properties
oCompany.CompanyDB = "Test_Db"
oCompany.UserName = "manager"
oCompany.Password = "manager"
oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2005
oCompany.UseTrusted = True
ocompany.CompanyDB = "YOURCOMPANYNAME"
TIP: I suggest to store the manager username and password / db UserName as Password / Company db name in ini file or registry, it is easier to load it from there than keep it hardcoded.
Regards
János
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
94 | |
11 | |
11 | |
6 | |
6 | |
4 | |
3 | |
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.