Print Page | Close Window

OutOfMemoryException Saving Entities

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3211
Printed Date: 13-May-2026 at 1:03am


Topic: OutOfMemoryException Saving Entities
Posted By: murray.bryant
Subject: OutOfMemoryException Saving Entities
Date Posted: 11-Jan-2012 at 9:48pm
Hi

I am loading a large number of entities and then trying to save. This is part of a load module loading historic data into the system.

I can load the data from source into memory. But as soon as I try to save I get a System.OutOfMemoryException.

Is there a limit to the number of entities I can try to save at once? I know there is a 1gb limit on the .net process but I have done testing where by the process is around 400mb and it still instantly fails on saving.

Do you have any ideas how I can work out what this limit is on a machine. 

Output attached below.

App is WPF

thanks

Murray




System.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled exception</Description><AppDomain>RingKing.vshost.exe</AppDomain><Exception><ExceptionType>IdeaBlade.EntityModel.EntityManagerSaveException, IdeaBlade.EntityModel, Version=6.1.4.0, Culture=neutral, PublicKeyToken=287b5094865421c0</ExceptionType><Message>Exception of type 'System.OutOfMemoryException' was thrown.</Message><StackTrace>   at IdeaBlade.EntityModel.AsyncProcessor`1.&amp;lt;&amp;gt;c__DisplayClass2.&amp;lt;.ctor&amp;gt;b__0(TArgs args)
   at IdeaBlade.EntityModel.AsyncProcessor`1.Signal()
   at IdeaBlade.EntityModel.AsyncProcessor`1.&amp;lt;Execute&amp;gt;b__5(Object x)
   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()</StackTrace><ExceptionString>IdeaBlade.EntityModel.EntityManagerSaveException: Exception of type 'System.OutOfMemoryException' was thrown. ---&amp;gt; System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at IdeaBlade.EntityModel.EntityServerProxy.CheckConnection(Exception e)
   at IdeaBlade.EntityModel.EntityServerProxy.ExecFunc[T](Func`1 func, Boolean funcWillHandleException)
   at IdeaBlade.EntityModel.EntityServerProxy.ExecuteOnServer[T](Func`1 func, Boolean funcWillHandleException)
   at IdeaBlade.EntityModel.EntityServerProxy.SaveChanges(SaveWorkState workState)
   at IdeaBlade.EntityModel.EntityManager.SaveEntitiesCore(SaveWorkState workState)
   --- End of inner exception stack trace ---
   at IdeaBlade.EntityModel.AsyncProcessor`1.&amp;lt;&amp;gt;c__DisplayClass2.&amp;lt;.ctor&amp;gt;b__0(TArgs args)
   at IdeaBlade.EntityModel.AsyncProcessor`1.Signal()
   at IdeaBlade.EntityModel.AsyncProcessor`1.&amp;lt;Execute&amp;gt;b__5(Object x)
   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()</ExceptionString><InnerException><ExceptionType>System.OutOfMemoryException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Exception of type 'System.OutOfMemoryException' was thrown.</Message><StackTrace>   at IdeaBlade.EntityModel.EntityServerProxy.CheckConnection(Exception e)
   at IdeaBlade.EntityModel.EntityServerProxy.ExecFunc[T](Func`1 func, Boolean funcWillHandleException)
   at IdeaBlade.EntityModel.EntityServerProxy.ExecuteOnServer[T](Func`1 func, Boolean funcWillHandleException)
   at IdeaBlade.EntityModel.EntityServerProxy.SaveChanges(SaveWorkState workState)
   at IdeaBlade.EntityModel.EntityManager.SaveEntitiesCore(SaveWorkState workState)</StackTrace><ExceptionString>System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at IdeaBlade.EntityModel.EntityServerProxy.CheckConnection(Exception e)
   at IdeaBlade.EntityModel.EntityServerProxy.ExecFunc[T](Func`1 func, Boolean funcWillHandleException)
   at IdeaBlade.EntityModel.EntityServerProxy.ExecuteOnServer[T](Func`1 func, Boolean funcWillHandleException)
   at IdeaBlade.EntityModel.EntityServerProxy.SaveChanges(SaveWorkState workState)
   at IdeaBlade.EntityModel.EntityManager.SaveEntitiesCore(SaveWorkState workState)</ExceptionString></InnerException></Exception></TraceRecord>



Replies:
Posted By: smi-mark
Date Posted: 12-Jan-2012 at 6:29am
Honestly, if you are loading bulk data Entity Framework isn't really the answer. How much data are you loading? Have you looked into using BulkCopy?

One option is to do it in batches, say every 200-300 records call a save, then continue.


Posted By: murray.bryant
Date Posted: 12-Jan-2012 at 3:52pm
Ok thanks. I know I could use bulk copy but that limits me to sql server. There is a chance I will have to support another database in the future so would like to load through devforce.

I am now having another issue.

When I call a save I am getting the following error

--
The transaction associated with the current connection has completed but has not been disposed.  The transaction must be disposed before the connection can be used to execute SQL statements.

--

Are my batches still to big?

Or is this related to something else.

Thanks

Murray



Posted By: matt.cavagnaro
Date Posted: 10-Sep-2012 at 1:09pm
I'm seeing the same error. From http://drc.ideablade.com/xwiki/bin/view/Documentation/understand-timeouts - what I've read this looks like some kind of timeout issue. Not sure how to work around this yet though.

Reading more about the SaveOptions now, but would be curious to know what other people think.


Posted By: sbelini
Date Posted: 13-Sep-2012 at 9:33am
Hi Matt,
 
It's unlikely that a timeout would cause an OutOfMemoryException. (maybe the other way around)
 
Approx how many entities are you trying to save when the issue happens? Are they all of the same type? How are they related?
 
Silvio.



Print Page | Close Window