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?
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?
If the process is terminated, all the OS resources, including network connections, will be released. In other words - that's fine.
If the application ends, the connection gets closed, along with everything else that was opened.
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:
© 2022 - 2024 — McMap. All rights reserved.