.NET Windows Service produces Exception errors?

R

Richard

I have created a Windows service which performs various functions
including setting variables in other application objects.

When the service runs under Local System account the functionality all
works OK, however when service runs under a user account it produces
exception errors when trying to set variables in the application
objects.

I created a .exe test harness which does the same and works OK when
run by the same user.

Anybody have any ideas on:
What is the difference when compiled as service compared to
application?
Why this works with service running under LocalSystem account and not
user account?
How can I get this to work with a user account?


Regards
Richard Marder
 
J

Jay B. Harlow [MVP - Outlook]

Richard,
Without knowing specifically what "other application objects" you are using
and what exceptions you are receiving, its hard to say how to get it to
work.

Can you provided a complete yet short example of what you are attempting (10
to 20 lines of actual code) along with the exception you are receiving?

Hope this helps
Jay
 
S

Simon Berman

Jay,

I am replying on behalf of Richard.

On our a Windows 2000 Production database server, a .NET Windows Service
called the PDCProcessor is unable to communicate with MapObjects COM
code to spatially register a point.

The box has the .NET Framework 1.0 and SDK installed and uses MapObjects
2.3.

Any ideas would be great!

1. This exception is thrown when we attempt to connect to the spatial
database to spatially register a point.

Event Type: Error
Event Source: PDCProcessor
Event Category: None
Event ID: 1
Date: 09/11/2004
Time: 16:08:06
User: N/A
Computer: RIMVDBS02
Description:
The description for Event ID ( 1 ) in Source ( PDCProcessor ) cannot be
found. The local computer may not have the necessary registry
information or message DLL files to display messages from a remote
computer. The following information is part of the event: 2004-11-09
16:08:06,817 [5308] FATAL Logica.RIMNET3.DAL.clsSpatialConnection -
SystemException Exception Type = System.InvalidCastException
Exception Message = QueryInterface for interface
ESRI.MapObjects2.Core.IMoDataConnection failed.
Exception Stack = at System.RuntimeType.InvokeDispMethod(String name,
BindingFlags invokeAttr, Object target, Object[] args, Boolean[]
byrefModifiers, Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags
invokeAttr, Binder binder, Object target, Object[] args,
ParameterModifier[] modifiers, CultureInfo culture, String[]
namedParameters)
at System.RuntimeType.ForwardCallToInvokeMember(String memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at ESRI.MapObjects2.Core.DataConnectionClass.set_Server(String A_1)
at Logica.RIMNET3.DAL.clsSpatialConnection.connectSDE(Boolean
boolRefDB)
..


2. This exception is thrown when we attempt to convert a grid reference
to an easting-northing.

Event Type: Error
Event Source: PDCProcessor
Event Category: None
Event ID: 0
Date: 09/11/2004
Time: 16:09:41
User: N/A
Computer: RIMVDBS02
Description:
The description for Event ID ( 0 ) in Source ( PDCProcessor ) cannot be
found. The local computer may not have the necessary registry
information or message DLL files to display messages from a remote
computer. The following information is part of the event: 2004-11-09
16:09:41,055 [3940] ERROR Logica.RIMNET3.GAD.clsPointConversion -
Exception: System.InvalidCastException
Message: QueryInterface for interface ESRI.MapObjects2.Core.IMoPoint
failed.
Source: mscorlib
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags
invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers,
Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags
invokeAttr, Binder binder, Object target, Object[] args,
ParameterModifier[] modifiers, CultureInfo culture, String[]
namedParameters)
at System.RuntimeType.ForwardCallToInvokeMember(String memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at ESRI.MapObjects2.Core.PointClass.set_X(Double A_1)
at
Logica.RIMNET3.GAD.clsPointConversion.gridRefToEastingNorthing(String
strGridRef, enmProjectionTypes& i32Projection)

..

3. The code that generates the second exception is:

Imports ESRI.MapObjects2.Core
Imports Logica.RIMNET3.DataAccess.Framework
Imports Logica.RIMNET3.DataAccess.SqlServer
Imports Logica.RIMNET3.common

Public Function gridRefToEastingNorthing(ByVal strGridRef As String,
ByRef i32Projection As enmProjectionTypes) As Point


'-----------------------------------------------------------------------
---
' Declarations

'-----------------------------------------------------------------------
---
Dim objPoint As Point


'-----------------------------------------------------------------------
---
' Database Declarations

'-----------------------------------------------------------------------
---
Dim objRequest As New DARequest()
Dim objFactory As DAFactory
Dim i32Easting As Int32
Dim i32Northing As Int32

Try

'-----------------------------------------------------------------------
---
' Setup the stored procedure

'-----------------------------------------------------------------------
---
objFactory = New SqlDataAccessHelper(m_i32OperatingMode)
objRequest.Command =
m_strSP_CONVERT_GRID_REF_TO_EAST_NORTH


'-----------------------------------------------------------------------
---
' Setup the parameters

'-----------------------------------------------------------------------
---
objRequest.PopulateParams(m_strARG_GRID_REF, strGridRef,
False)
objRequest.PopulateParams(m_strARG_REGION_CODE, "",
True)
objRequest.PopulateParams(m_strARG_EASTING, i32Easting,
True)
objRequest.PopulateParams(m_strARG_NORTHING,
i32Northing, True)


'-----------------------------------------------------------------------
---
' Get the converted NGR value

'-----------------------------------------------------------------------
---
objFactory.ExecuteNonQuery(objRequest)

If Not objRequest.GetParamValue(m_strARG_REGION_CODE) Is
System.DBNull.Value _
AndAlso Not
objRequest.GetParamValue(m_strARG_EASTING) Is System.DBNull.Value _
AndAlso Not
objRequest.GetParamValue(m_strARG_NORTHING) Is System.DBNull.Value Then

Select Case
CStr(objRequest.GetParamValue(m_strARG_REGION_CODE))
Case m_strGRID_CODE_GB
i32Projection =
enmProjectionTypes.BritishNationalGrid
Case m_strGRID_CODE_IE
i32Projection =
enmProjectionTypes.IrishNationalGrid
Case m_strGRID_CODE_CI
i32Projection =
enmProjectionTypes.ChannelIslands
End Select

objPoint = New Point()
objPoint.X =
CDbl(objRequest.GetParamValue(m_strARG_EASTING))
objPoint.Y =
CDbl(objRequest.GetParamValue(m_strARG_NORTHING))

End If

Catch objDAExcp As DAException
If m_objLog.IsErrorEnabled Then
m_objLog.Error(objDAExcp)

Catch objExcp As Exception
If m_objLog.IsErrorEnabled Then m_objLog.Error(objExcp)

End Try


'-----------------------------------------------------------------------
---
' Return from the function

'-----------------------------------------------------------------------
---
If IsNothing(i32Projection) Or IsNothing(objPoint) Then
Throw New EastNorthNotObtainedException()
Else
Return objPoint
End If

End Function
 
J

Jay B. Harlow [MVP - Outlook]

Simon,
Sorry for the delay, holidays & what ever...

Are you certain that the MapObjects on your server is the same level as on
your development box?

The System.InvalidCastException would suggest that you may be looking for a
newer COM object (newer GUID) or a COM object that simply is not supported
in the version on your server.


Can you run the service, as a service, on the development box. Does it work?
It may be an authority thing with how services run.

Hope this helps
Jay




Simon Berman said:
Jay,

I am replying on behalf of Richard.

On our a Windows 2000 Production database server, a .NET Windows Service
called the PDCProcessor is unable to communicate with MapObjects COM
code to spatially register a point.

The box has the .NET Framework 1.0 and SDK installed and uses MapObjects
2.3.

Any ideas would be great!

1. This exception is thrown when we attempt to connect to the spatial
database to spatially register a point.

Event Type: Error
Event Source: PDCProcessor
Event Category: None
Event ID: 1
Date: 09/11/2004
Time: 16:08:06
User: N/A
Computer: RIMVDBS02
Description:
The description for Event ID ( 1 ) in Source ( PDCProcessor ) cannot be
found. The local computer may not have the necessary registry
information or message DLL files to display messages from a remote
computer. The following information is part of the event: 2004-11-09
16:08:06,817 [5308] FATAL Logica.RIMNET3.DAL.clsSpatialConnection -
SystemException Exception Type = System.InvalidCastException
Exception Message = QueryInterface for interface
ESRI.MapObjects2.Core.IMoDataConnection failed.
Exception Stack = at System.RuntimeType.InvokeDispMethod(String name,
BindingFlags invokeAttr, Object target, Object[] args, Boolean[]
byrefModifiers, Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags
invokeAttr, Binder binder, Object target, Object[] args,
ParameterModifier[] modifiers, CultureInfo culture, String[]
namedParameters)
at System.RuntimeType.ForwardCallToInvokeMember(String memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at ESRI.MapObjects2.Core.DataConnectionClass.set_Server(String A_1)
at Logica.RIMNET3.DAL.clsSpatialConnection.connectSDE(Boolean
boolRefDB)
.


2. This exception is thrown when we attempt to convert a grid reference
to an easting-northing.

Event Type: Error
Event Source: PDCProcessor
Event Category: None
Event ID: 0
Date: 09/11/2004
Time: 16:09:41
User: N/A
Computer: RIMVDBS02
Description:
The description for Event ID ( 0 ) in Source ( PDCProcessor ) cannot be
found. The local computer may not have the necessary registry
information or message DLL files to display messages from a remote
computer. The following information is part of the event: 2004-11-09
16:09:41,055 [3940] ERROR Logica.RIMNET3.GAD.clsPointConversion -
Exception: System.InvalidCastException
Message: QueryInterface for interface ESRI.MapObjects2.Core.IMoPoint
failed.
Source: mscorlib
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags
invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers,
Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags
invokeAttr, Binder binder, Object target, Object[] args,
ParameterModifier[] modifiers, CultureInfo culture, String[]
namedParameters)
at System.RuntimeType.ForwardCallToInvokeMember(String memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at ESRI.MapObjects2.Core.PointClass.set_X(Double A_1)
at
Logica.RIMNET3.GAD.clsPointConversion.gridRefToEastingNorthing(String
strGridRef, enmProjectionTypes& i32Projection)

.

3. The code that generates the second exception is:

Imports ESRI.MapObjects2.Core
Imports Logica.RIMNET3.DataAccess.Framework
Imports Logica.RIMNET3.DataAccess.SqlServer
Imports Logica.RIMNET3.common

Public Function gridRefToEastingNorthing(ByVal strGridRef As String,
ByRef i32Projection As enmProjectionTypes) As Point


'-----------------------------------------------------------------------
---
' Declarations

'-----------------------------------------------------------------------
---
Dim objPoint As Point


'-----------------------------------------------------------------------
---
' Database Declarations

'-----------------------------------------------------------------------
---
Dim objRequest As New DARequest()
Dim objFactory As DAFactory
Dim i32Easting As Int32
Dim i32Northing As Int32

Try

'-----------------------------------------------------------------------
---
' Setup the stored procedure

'-----------------------------------------------------------------------
---
objFactory = New SqlDataAccessHelper(m_i32OperatingMode)
objRequest.Command =
m_strSP_CONVERT_GRID_REF_TO_EAST_NORTH


'-----------------------------------------------------------------------
---
' Setup the parameters

'-----------------------------------------------------------------------
---
objRequest.PopulateParams(m_strARG_GRID_REF, strGridRef,
False)
objRequest.PopulateParams(m_strARG_REGION_CODE, "",
True)
objRequest.PopulateParams(m_strARG_EASTING, i32Easting,
True)
objRequest.PopulateParams(m_strARG_NORTHING,
i32Northing, True)


'-----------------------------------------------------------------------
---
' Get the converted NGR value

'-----------------------------------------------------------------------
---
objFactory.ExecuteNonQuery(objRequest)

If Not objRequest.GetParamValue(m_strARG_REGION_CODE) Is
System.DBNull.Value _
AndAlso Not
objRequest.GetParamValue(m_strARG_EASTING) Is System.DBNull.Value _
AndAlso Not
objRequest.GetParamValue(m_strARG_NORTHING) Is System.DBNull.Value Then

Select Case
CStr(objRequest.GetParamValue(m_strARG_REGION_CODE))
Case m_strGRID_CODE_GB
i32Projection =
enmProjectionTypes.BritishNationalGrid
Case m_strGRID_CODE_IE
i32Projection =
enmProjectionTypes.IrishNationalGrid
Case m_strGRID_CODE_CI
i32Projection =
enmProjectionTypes.ChannelIslands
End Select

objPoint = New Point()
objPoint.X =
CDbl(objRequest.GetParamValue(m_strARG_EASTING))
objPoint.Y =
CDbl(objRequest.GetParamValue(m_strARG_NORTHING))

End If

Catch objDAExcp As DAException
If m_objLog.IsErrorEnabled Then
m_objLog.Error(objDAExcp)

Catch objExcp As Exception
If m_objLog.IsErrorEnabled Then m_objLog.Error(objExcp)

End Try


'-----------------------------------------------------------------------
---
' Return from the function

'-----------------------------------------------------------------------
---
If IsNothing(i32Projection) Or IsNothing(objPoint) Then
Throw New EastNorthNotObtainedException()
Else
Return objPoint
End If

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top