New Posts New Posts RSS Feed: OutOfMemoryException Saving Entities
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

OutOfMemoryException Saving Entities

 Post Reply Post Reply
Author
murray.bryant View Drop Down
Groupie
Groupie


Joined: 11-Jan-2012
Location: Australia
Posts: 44
Post Options Post Options   Quote murray.bryant Quote  Post ReplyReply Direct Link To This Post Topic: OutOfMemoryException Saving Entities
    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>
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
murray.bryant View Drop Down
Groupie
Groupie


Joined: 11-Jan-2012
Location: Australia
Posts: 44
Post Options Post Options   Quote murray.bryant Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
matt.cavagnaro View Drop Down
Newbie
Newbie


Joined: 09-Aug-2012
Posts: 7
Post Options Post Options   Quote matt.cavagnaro Quote  Post ReplyReply Direct Link To This Post Posted: 10-Sep-2012 at 1:09pm
I'm seeing the same error. From 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.
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down