我有时在更新我的sql compact数据库时遇到此异常。 错误如下:
2/6/2017 11:06:08 AM ERROR IN SavePacket(EnergyMeter_Grid e) data into file
System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.Entity.Core.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlServerCe.SqlCeException: The database file is larger than the configured maximum database size. This setting takes effect on the first concurrent database connection only. [ Required Max Database Size (in MB; 0 if unknown) = 21 ]
at System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 hr)
at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommandText(IntPtr& pCursor, Boolean& isBaseTableCursor)
at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)
at System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery()
at System.Data.Entity.SqlServerCompact.SqlCeMultiCommand.ExecuteNonQuery()
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)
at System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues)
at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
--- End of inner exception stack trace ---
at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
at System.Data.Entity.Internal.InternalContext.SaveChanges()
--- End of inner exception stack trace ---
at System.Data.Entity.Internal.InternalContext.SaveChanges()
at ILS.DB.DbUpdateLoop.SavePacket(EnergyMeter_Grid e)
我知道这可能是造成尺寸的原因,因为其他日子我手动将我的数据库的大小设为4 GB。
using (var context = Context.Create("C:\\XSR_BIB_V2\\XSR_BIB_V2_DATABASE.sdf", "", 4091))
{
if (DbUpdateLoop.context.Database.Connection.State == System.Data.ConnectionState.Closed)
DbUpdateLoop.context.Database.Connection.Open();
}
这个例外不会影响我的功能,但我很好奇是可能出错的。这个异常通常发生在这个名为SavePacket(EnergyMeter_Grid e)
的地方,你可以从上面的异常日志中看到。
savePacket(energyMeter grid e)代码::::
if (DbUpdateLoop.context.Database.Connection.State == System.Data.ConnectionState.Closed)
{
DbUpdateLoop.context.Database.Connection.Open();
}
if (e == null)
throw new ArgumentNullException("Energy Meter Packet");
EnergyMeter_Grid eInfo = new EnergyMeter_Grid(e.MeterId, e.KW, e.KWh, e.EId);
using (context.Database.BeginTransaction())
{
context.EnergyMeter_GridTbl.Add(eInfo);
}
context.SaveChanges();
代码的解释:它很简单,我正在做的就是打开一个上下文并将energyMeter_gridtable值作为param转换为sql compact db并保存更改。
would love if someone one tell me why this error is happening and what should i do to resolve it??