Search code examples
c#winformsentity-frameworksql-server-ce

The data area passed to a system call is too small when saving with C# EF6


I have a C#, Winforms EF6 application. Database is SQL Server Compact 4. In some computers (most work fine) I get the Exception "The data area passed to a system call is too small" when saving a simple object like in the code below

        public void Add(SimpleObject simpleObject)
        {
            try
            {
                using (var db = new MyDbContext())
                {
                    db.SimpleObjects.AddOrUpdate(e => e.Description, simpleObject);
                    db.SaveChanges();
                }
            }
            catch(Exception ex)
            {
                _logger.ErrorException("Add", ex);
                throw;
            }
        }

SimpleObject is extremely simple with 2 columns ([ID] INT NOT NULL IDENTITY (1,1), [DESCRIPTION] NVARCHAR(4000)). The instances that throw exceptions have in the Description field common text (bellow 150 characters) that are in most computers normally saved. Command AddOrUpdate throws the exception.

Full Exception details logged with NLog:

System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> System.Data.SqlServerCe.SqlCeException: The data area passed to a system call is too small. 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.Entity.SqlServerCompact.SqlCeMultiCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func3 operation, TInterceptionContext interceptionContext, Action3 executing, Action3 executed) at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext) at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) --- End of inner exception stack trace --- at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues) at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) at System.Data.Entity.Core.Objects.ObjectQuery1.<>c__DisplayClass7.b__5() at System.Data.Entity.Core.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption) at System.Data.Entity.Core.Objects.ObjectQuery1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0() at System.Data.Entity.Internal.LazyEnumerator1.MoveNext() at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 source) at System.Data.Entity.Migrations.DbSetMigrationsExtensions.AddOrUpdate[TEntity](DbSet1 set, IEnumerable1 identifyingProperties, InternalSet1 internalSet, TEntity[] entities) at System.Data.Entity.Migrations.DbSetMigrationsExtensions.AddOrUpdate[TEntity](IDbSet1 set, Expression1 identifierExpression, TEntity[] entities)>

Any help would be highly appreciated!


Solution

  • You should upgrade to SQL CE 4.0 SP1, as it contains a fix for that issue - see http://erikej.blogspot.com/2012/03/sql-server-compact-40-sp1-ctp1.html