I have a C# application that writes to an encrypted SQL Server Compact database. This is the code:
conn = new SqlCeConnection(connectionString);
ConnectionOpen();
SqlCeCommand cmd = conn.CreateCommand();
cmd.CommandText = "INSERT INTO TableName ([Date],[ParentURL],[ChildURL],[DateLongFormat]) VALUES (@EntryDate ,@parentUrl,@childUrl,@EntryDateLong)";
cmd.Parameters.AddWithValue("@EntryDate", EntryDate);
cmd.Parameters.AddWithValue("@parentUrl", parentUrl);
cmd.Parameters.AddWithValue("@childUrl", childUrl);
cmd.Parameters.AddWithValue("@EntryDateLong", EntryDate.ToString("yyyy/MM/dd hh:mm:ss.fff"));
int count = cmd.ExecuteNonQuery();
cmd.Dispose();
ConnectionClose();
Very occasionally (roughly 1/500 times) the EXE will crash throwing the following two errors (retrieved via Event Viewer Application Log):
[Source = .NET Runtime]
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
Stack:
at System.Data.SqlServerCe.SqlCeCommand.ReleaseNativeInterfaces()
at System.Data.SqlServerCe.SqlCeCommand.Dispose(Boolean)
at System.Data.SqlServerCe.SqlCeCommand.Finalize()
[Source = Application Error]
Exception code: 0xc0000005
Fault offset: 0x000000000005030e
Faulting module path: C:\Program Files\Microsoft SQL Server Compact Edition\v4.0\sqlcese40.dll
Originally I thought that the error was caused by two threads trying to write simultaneously to the database, but SQL Server Compact supports multi-threading. I also changed the SQL Server Compact database schema to support string values with huge character limits, so it's not because its trying to write a string longer than the cell value either.
All of my C# code is executed within a try/catch, anyone know why the application is crashing, or what these stack traces signify?