native exception not caught with try-catch

native exception not caught with try-catch

Post by bWF0dmR » Sat, 23 Feb 2008 20:14:02

I have developed an application in and recently have started to get
native exceptions. When running the application on the device I get an error
that says "A native exception has occurred in ....." and it gives me two
buttons - details or quit.

When viewing details it gives me:

ExceptionCode: 0xc0000005
ExceptionAddress: 0x006c0044
Reading: 0x006c0044

at NativeMethods.OpenStore(IntPtr pOpenInfo, IntPtr pfnOnFlushFailure,
IntPtr& pStoreService, IntPtr& pStoreServer, IntPtr& pQpServices, IntPtr&
pSeStore, IntPtr& pTx, IntPtr& pQpDatabase, IntPtr& pQpSession, IntPtr&
pStoreEvents, IntPtr& pError)
at SqlCeConnection.Open(Boolean silent)
at rmcRemoteConnection.get_LocalConnection()
at rmcRemoteConnection.ExecuteCommand(String SQLStr, SqlCeCommand Command)
at rmcRemoteConnection.ExecuteCommand(SqlCeCommand Command)
at kWGlobal.ExecuteCommand(SqlCeCommand cmd)
at ComponentGlobal.SendDataTokWatch()
at ComponentGlobal.IntervalTime(Object state)
at Timer.ring()

The code within ComponentGlobal.IntervalTime is:

Private Shared Sub IntervalTime(ByVal state As Object)
'This is fired whenever the time is passed
Dim DatS As datDataSource
Dim BaseTime As New Date(2000, 1, 1)

For Each DatS In DataSources

If (NextIntervalDueDate.Subtract(BaseTime).TotalMilliseconds
Mod DatS.Interval) = 0 Then
'This means the correct number of intervals has passed
End If


'Set the next timeout period

Catch ex As Exception
End Try

End Sub

As you can see the entire function is within a try-catch but the error is
not caught. This is a major issue as the reliability of the application is

If anyone can help it would be much appreciated.


native exception not caught with try-catch

Post by » Sat, 23 Feb 2008 21:10:30

Sure, that's an access violation, so it's no surprise that it's not caught.
What scenario causes this? Is it after the device wakes up from a slaeep
state and then tried to access a database on a persistent store?


Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community


native exception not caught with try-catch

Post by Peter Foo » Sat, 23 Feb 2008 21:14:36

Try/catch cannot catch native exceptions. The issue here is the code is
trying to read from some memory location where it shouldn't. Since it
appears to be occuring with SqlCe code what version of SqlCe and .NETCF are
you using and on what platform? What exactly are you doing within the
SendDataTokWatch method?


Peter Foot
Microsoft Device Application Development MVP |
In The Hand Ltd - .NET Solutions for Mobility

native exception not caught with try-catch

Post by bWF0dmR » Sat, 23 Feb 2008 22:23:00


I am using .NETCF 3.5
SQLCe version 3.5
The target platform is window CE5.0 on a SBX255 hardware platform

The code that uses SQLCe is detailed below.
Public Function ExecuteCommand(ByVal SQLStr As String, ByVal Command As
SqlCeCommand) As Integer
Dim ErrorCount As Integer = 0
Dim CmdPassed As Boolean = Nothing
If Command Is Nothing Then
If CmdPassed = Nothing Then CmdPassed = False
Command = New SqlCeCommand(SQLStr, LocalConnection)
If CmdPassed = Nothing Then CmdPassed = True
If Len(SQLStr) > 0 Then
Command.CommandText = SQLStr
End If
If Command.Connection Is Nothing Then
Command.Connection = LocalConnection()
End If
End If
ExecuteCommand = Command.ExecuteNonQuery()

If CmdPassed = False Then
End If

Catch ex As Exception
If ErrorCount < 3 Then
ErrorCount = ErrorCount + 1
Command.Connection = Nothing
If ErrorCount > 1 Then
'here we will reset the LocalConnection just in case
'this is the issue
End If
GoTo TryAgain
If kWatchClasses.kWGlobal.LogErrors Then
End If
'Re-throw the error at this point
End If
End Try

End Function

I am getting this error very regularily now and it is consistantly happening
within sqlce. The error below occured when opening a connection while Ihave
detailed one below were I am executing a command - the code above relates to
the function ExecuteCommand.

This code has been used for some-time without errors.

Could it be possible that the database structure is causing this error? So
far the two errors detailed in this thread have related to SQLCe and one was
opening a new connection while the other relates to executing a command.

ExceptionCode: 0xc0000005
ExceptionAddress: 0x01b62994
Reading: 0x00000000
Faulting module: sqlceme35.dll
Offset: 0x00002994

at NativeMethods.CreateCommand(IntPtr pQpSession, IntPtr& pQpCommand,
IntPtr pError)
at SqlCeCommand.InitializeCommand(CommandBehavior behavior, String method)
at SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method,
ResultSetOptions options)
at SqlCeCommand.ExecuteNonQuery()
at rmcRemoteConnection.ExecuteCommand(String SQLStr, SqlCeCommand Command)
at kWMainModule.UpdateTableProperty(String TableName, String
PropertyName, String IdentityName, Int32 IdentityValue, Object PropertyValue)
at kWMessageSend.set_Attempts(Int16 value)
at kWMessageSend.Send()
at rmcRemoteConnection.MessagesSendingSEND()
at rmcRemoteConnection.TimerEvent(Object state)
at Timer.ring()


"Peter Foot" wrote:


native exception not caught with try-catch

Post by Harry Simp » Sat, 23 Feb 2008 23:23:30

Microsoft is currently looking at a project that I sent to them which does
this. there's a slight possiblity that 3.5 and even 2 SPx are not totally
backward compatible.
I can get mine to work without error if I replace the CF version on the
device with CF2 RTM - everyting works great. But if I let the debug copy
over the latest version (3.5) - native errorsville.
Hope this helps

native exception not caught with try-catch

Post by bWF0dmR » Sat, 23 Feb 2008 23:35:01


Do you now if SQLCe 3.5 will work with CF 2 - there are a number of fixes in
SQLCe 3.5 that I require. I assume that you app also used CF 3.5 and SQLCe

native exception not caught with try-catch

Post by bWF0dmR » Sun, 24 Feb 2008 00:19:01

found the issue - turned out to be a badly formated SQL string causing all
the trouble. Just was very hard to find because it did not raise the error

The guilty code is
UPDATE datData
SET SentTokWatch = 1
AND DataID IN (3,4,5,6,7,8,9,11,12,13,14)

AND should be WHERE

When I eventually found the error I was able to step throught he code and
occasionaly was able to extract the following error messages. The native
error was not always generated immediatly and I would guess that the issue
caused by the above statement resulted in an unstable enviroment - so
therefore the actual native error message box sometimes was generated
elsewhere - that's my guesss.

{" [ 1,37,AND ]"}
Errors: {System.Data.SqlServerCe.SqlCeErrorCollection}
HResult: -2147217900
InnerException: Nothing
Message: " [ 1,37,AND ]"
NativeError: 25501
Source: "SQL Server Compact ADO.NET Data Provider"
StackTrace: " at
System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 hr) at
System.Data.SqlServerCe.SqlCeCommand.CompileQueryPlan() at
System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior,
String method, ResultSetOptions options) at
System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery() at
kWatchDemandControlerV1.rmcRemoteConnection.ExecuteCommand(String SQLStr,
SqlCeCommand Command) at
Command) at kWatchClasses.kWGlobal.ExecuteCommand(SqlCeCommand cmd) at
ioInputOutputComponent.ComponentGlobal.SendDataTokWatch() at
ioInputOutputComponent.ComponentGlobal.IntervalTime(Object state) at
System.Threading.Timer.ring() "

Anyway - thanks for all your help.

"matvdl" wrote: