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