Reputation:
I am querying the db in a separate thread.
If I close the application while the query is being executed, will the SqlConnection automatically close or will it remain open?
Upvotes: 9
Views: 3423
Reputation: 6651
A SqlConnection is a disposable object. In general it is always good practice to Dispose() of objects that implement IDisposable. I also noticed SqlConnection objects have a Close() method. Should you call that too? Well, I found this article with more info on this:
SqlConnection: To Close or To Dispose?
Upvotes: 0
Reputation: 81675
If the application ends, the connection gets closed, along with everything else that was opened.
Upvotes: 0
Reputation: 1503419
If the process is terminated, all the OS resources, including network connections, will be released. In other words - that's fine.
Upvotes: 9