I was debugging Jaroslaw Kowalski provider wrappers. While debugging it I observed that the Entity Framework closes the connection after every query. On every interaction with database, during the lifetime of application, a database connection is opened and after performing the query the connection is closed
My questions are:
The thing that is bothering me is that Entity Framework itself is closing the connection. So I am a little hesitant to pool the connection or it may cause problems in exceptional scenarios.
FYI:
The EF only closes connections it opens.
So if you do something like this manually:
((ctx.Connection as EntityConnection).StoreConnection as SqlConnection).Open();
subsequents queries and SaveChanges()
shouldn't close that connection.
Hope this helps
Alex
The default connectionpool = 1 connection. So don't worry.
The whole idea here is that we have 1 programming model (disconnected) and that configuration & tuning is external.
In .Net 4, to quote: Managing Connections and Transactions
The following considerations apply when managing connections:
The object context will open the connection if it is not already open before an operation. If the object context opens the connection during an operation, it will always close the connection when the operation is complete.
If you manually open the connection, the object context will not close it. Calling Close or Dispose will close the connection.
If the object context creates the connection, the connection will always be disposed when the context is disposed.
In a long-running object context, you must ensure that the context is disposed when it is no longer required.
If you supply an open EntityConnection for the object context, you must ensure that it is disposed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.