Sql Compact randomly throws AccessViolationException

I am running Sql Server Compact Edition 3.5.1.0 SP1 in a multi-threaded application. The application randomly runs insert requests in transactions. With short transactions, it works fine. But when the transactions get longer and the delay between execution gets shorter or when I launch the application in debug mode, SqlCE starts accidentally throwing the following exception:

AccessViolationException Attempted to read or write protected memory. This often indicates that other memory is corrupted.

in System.Data.SqlServerCe.SqlCeCommand.CompileQueryPlan () in System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand (CommandBehavior behavior, String method, Parameters ResultSetOptions) with System.Data.SqlServerCe.SqlCecTectComtTectComtTectComtTemTectComtTectCommTecTectCommTectComtectComtectComtectcomtectcomtectcomtectcomtectcomtectcomtectcomtectcomtectcomtectcomtectcomtectcomtectcomtectcomtectcomtectcomtectcomtectcomtectcomtcomtec () in D: \ Projects \ PlayGround \ SqlCompactTest \ SqlCompactTest \ TransactedCommandGroupExecutionTest.cs: line 53 on SqlCompactTest.ExecutionTest.RunTest () in D: \ Projects \ PlayGround \ SqlCompactTest \ SqlComtTt.60ComtactTest.SqlComtTact.TextCtTact.Text .TimerElapsed (Sender Object, ElapsedEventArgs e) in D: \ Projects \ PlayGround \ SqlCompactTest \ SqlCompactTest \ ExecutionTest.cs: line 68 on System.Timers.Timer.MyTimerCallback (State Object)

The code I run is:

IDbConnection connection = m_connectionProvider.GetConnection(); // Just returns new connection

connection.Open();
IDbTransaction transaction = connection.BeginTransaction();

foreach (IDbCommand command in m_commands)
{
    command.Connection = connection;
    command.ExecuteNonQuery(); // This line throws exception
    Thread.Sleep((int)m_delayBetweenExecutions);
}

transaction.Commit();
connection.Close();

This code works simultaneously in two threads. Connection string:

"Data Source=testDB.sdf;Encrypt Database=True;Password=test;File Mode=Read Write;Persist Security Info=False;Max Database Size=1024"

, Framework 1.1, , / .., . Microsoft, , . - 3.5.0.0.

?

+5
2

, . , .

command.Connection = connection;
command.Connection.GetHashCode() == connection.GetHashCode(); // may return false.

. connection.CreateCommand();

+5

SQL CE . , ( ).

+3

Source: https://habr.com/ru/post/1015837/


All Articles