Last post Feb 29, 2016 08:58 AM by Yohann Lu
Feb 26, 2016 02:23 PM|starter88|LINK
Recently switched to entity
Should I close the connection using the Dispose method?
Feb 26, 2016 02:50 PM|Rion Williams|LINK
If you are using connections, its generally preferred to take advantage of the
using keyword, which will properly scope your connection and handle any closing / disposal for you :
using(var context = new YourDataContext())
// Use it here
// At this point, the connection has been closed and disposed of
Feb 26, 2016 05:17 PM|TechView|LINK
Hello starter88! Linq uses DataContext for database connections and it is being handled with the 'using' keyword. For more, you could refer to the following link:
Feb 29, 2016 08:58 AM|Yohann Lu|LINK
As Rion Williams said, you can use the using keyword. It is Automatically releases the connection after performing.
The following tutorial describes the behavior of the Entity Framework with regard to passing connections in the context and the functionality of the Database.Connection.Open() API: