If you are using Entity Framework, or any other ORM for that matter you need to head over to Hibernating Rhinos and buy a copy of Entity Framework Profiler, the license will pay for itself in no time flat.
When using any ORM, but in our case EF it is recommended, ok I would say required that you dispose or close your Data Context once you are done with your database transitions. Not closing the context will not immediately bring your system to its knees, but over time as your grow and scale you are going to start noticing memory and performance issues. Sure, you can let the .Net Garbage collector dispose of your context, but you really should be a responsible developer and clean up after yourself, trust me it is worth the effort.
When using EFProfiler you can very easily determine when you left a context dangling open, all you need to do is look at the timings on the executed statements as seen below.
Here is the code which produced the above
Now I am only showing you the creation of this because as you can assume it was NEVER closed.
To close this I could manually call the .Dispose method or I could use a using statement as seen here
By using the Using statement above I am explicitly telling the runtime to close the connection, thus freeing my resources and reducing my over head. The image below shows the statement now
As you can see you can find open connections w/ little ease using Entity Framework profiler.
Till next time,
03-29-2013 8:17 AM