on 01-07-2009 3:33 PM
Hi,
I am trying to create a Windows Service in Visual Basic (VB), that connects to an SAP system. The reason for using a Windows Service is, that it has to start up automatically on a server, regardless if a user logs on or not.
The program has to read data (using a BAPI) from SAP every 5 sec, and post is to a Microsoft Queue (MSMQ).
I have the functionality working in a dialog based application - but the problems is that is requires the user to log on, before it runs.
For that reason I am trying to convert the application to a Windows Service Application, which can be started automatically when the server is turned on/restarted.
But when I try to make the connection to SAP R/3 in the Windows Service Application the Connection object fails.
Dim oBAPICtrl As Object
Dim oLogonCtrl As Object
oBAPICtrl = CreateObject("SAP.BAPI.1";)
oLogonCtrl = CreateObject("SAP.Logoncontrol.1";)
oBAPICtrl.Connection = oLogonCtrl.NewConnection <-- this one fails
When I check the VB variable Err, which contains info on the current error, I read the following information (which tells me that I have access to the SAP.BAPI.1 object):
Err.source = SAP.BAPI
Err.Description = Application-defined or object-defined error
Err.number = -2147467259
A Windows Service requires you to state which account/user to "run" as, as I mention before no real user is logged in. I have tried both LocalSystem and as my own user.
Any one with a suggestion what to try??
Regards
Anders
BTW:
Visual Basic is VB 2008
SAP GUI is 7.1
<MOVED BY MODERATOR TO THE CORRECT FORUM>
Edited by: Alvaro Tejada Galindo on Jan 7, 2009 10:34 AM
Hi
I found the solution myself.
If I removed the line
'oBAPICtrl.Connection = oLogonCtrl.NewConnection
the code worked fine - and I could log in and call BAPI's with no problems.
I wonder what the difference is from the dialog application to the Service application - but right now I do not care - I just happy that is works.
regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.