【问题标题】:The data area passed to a system call is too small when saving with C# EF6使用 C# EF6 保存时传递给系统调用的数据区域太小
【发布时间】:2019-09-24 10:14:39
【问题描述】:

我有一个 C#、Winforms EF6 应用程序。数据库是 SQL Server Compact 4。 在某些计算机中(大多数工作正常),当保存如下代码中的简单对象时,出现异常“传递给系统调用的数据区域太小”

        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 非常简单,只有 2 列([ID] INT NOT NULL IDENTITY (1,1),[DESCRIPTION] NVARCHAR(4000))。引发异常的实例在“描述”字段中具有通常保存在大多数计算机中的通用文本(低于 150 个字符)。命令 AddOrUpdate 抛出异常。

使用 NLog 记录的完整异常详细信息:

System.Data.Entity.Core.EntityCommandExecutionException:执行命令定义时出错。有关详细信息,请参阅内部异常。 ---> System.Data.SqlServerCe.SqlCeException:传递给系统调用的数据区太小。 在 System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 小时) 在 System.Data.SqlServerCe.SqlCeCommand.CompileQueryPlan() 在 System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior 行为,String 方法,ResultSetOptions 选项) 在 System.Data.Entity.SqlServerCompact.SqlCeMultiCommand.ExecuteReader(CommandBehavior 行为) 在 System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func3 操作,TInterceptionContext 拦截上下文,Action3 executing, Action3 执行) 在 System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand 命令,DbCommandInterceptionContext 拦截上下文) 在 System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand,CommandBehavior 行为) --- 内部异常堆栈跟踪结束 --- 在 System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand,CommandBehavior 行为) 在 System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext 上下文,ObjectParameterCollection 参数值) 在 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() 在 System.Data.Entity.Core.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption) 在 System.Data.Entity.Core.Objects.ObjectQuery1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0() at System.Data.Entity.Internal.LazyEnumerator1.MoveNext() 在 System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 source) at System.Data.Entity.Migrations.DbSetMigrationsExtensions.AddOrUpdate[TEntity](DbSet1 集,IEnumerable1 identifyingProperties, InternalSet1 internalSet,TEntity[] 实体) 在 System.Data.Entity.Migrations.DbSetMigrationsExtensions.AddOrUpdate[TEntity](IDbSet1 set, Expression1 identifierExpression, TEntity[] 实体)>

任何帮助将不胜感激!

【问题讨论】:

  • 你为什么使用 AddOrUpdate?
  • 某些 AddOrUpdate 故障导致异常?

标签: c# winforms entity-framework sql-server-ce


【解决方案1】:

您应该升级到 SQL CE 4.0 SP1,因为它包含对该问题的修复 - 请参阅 http://erikej.blogspot.com/2012/03/sql-server-compact-40-sp1-ctp1.html

【讨论】:

  • 我会尝试并标记为答案,如果它有效。谢谢!
猜你喜欢
  • 2012-10-22
  • 1970-01-01
  • 2023-03-20
  • 1970-01-01
  • 2017-11-02
  • 1970-01-01
  • 2014-01-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多