We are having an intermittent application crash when using SQL CE 4 SP1 (4.0.8876.1), which happen every 1-2 days.
The crash is: Unhandled exception at 0x0000000077714102 (ntdll.dll) in WERBA8A.tmp.mdmp: 0xC0000374: A heap has been corrupted (parameters: 0x000000007778B4B0).
The error happen when doing a call to SqlCeResultSet.Close() (code sample bellow). The crash occur very infrequently, maybe once in several tens of thousands calls. When the error occur the whole application crashes (windows service).
Multiple queries are executed concurrently.
The stack trace is:
sqlceqp40.dll!operator delete(void *)
sqlceqp40.dll!QPCommandEnv::`vector deleting destructor'(unsigned int)
sqlceme40.dll!ME_SafeRelease(struct IUnknown * *)
[Managed to Native Transition]
[--Call to sqlCeResultSet.Close()--]
NOTE. We have a mini dump and an heap dump if required.
The crash does not only occur when calling Dispose() but also when calling ExecuteResultSet. The crash only occur when sharing the same connection between multiple commands and executing command simultaneously.
I added a small project which can replicate the problem. (see attachement). I also updated the "Steps to Reproduce" section and added a workaround.