DataContext Close
See original GitHub issueIf I run this Code
{
var db = new MyContext();
var x = db.SomeTable.ToList();
var y = db.SomeTable.ToList();
}
until context end i have 2 connections open (sleeping) on db, after context ends they are released.
but if i ran this code
{
var db = new MyContext();
db.OnTraceConnection = (e) =>
{
if (e.TraceInfoStep == TraceInfoStep.Completed || e.TraceInfoStep == TraceInfoStep.Error)
e.DataConnection.Close();
};
var x = db.SomeTable.ToList();
var y = db.SomeTable.ToList();
}
until context end i have 1 connections open(sleeping) on db, after context ends this is released.
Environment details
linq2db version: 2.9.0 Database Server: Microsoft Sql Server Database Provider: SqlServerVersion.v2017 Operating system: Windows .NET Framework: 4.7.2
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Does Linq to Sql close connections automatically? [duplicate]
No, the first version does not close the connection until the application context is disposed of (that is, when the application terminates). The ......
Read more >Connection management - EF6
But, regardless of that setting, the store connection is always closed when the context is disposed. So if you have more than one...
Read more >Method to re-open a connection on a datacontext if it has ...
The following method is used to keep a DataContext open if it is closed or broken and is called before most calls to...
Read more >[.NET development] How to automatically close your contexts
The first step is to implement the interface IDisposable and its “Dispose” method. In this method you just Dispose() your DbContext which will ......
Read more >How does Entity Framework know when to close ...
It appears that the DBContext will usually auto-close the connections as needed. That said, there are other problems with reusing an EF ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@croban, fix prepared. I hope it will be released next Thursday.
Also it is reproducible only for async version. Investigation needed.