user143887
user143887

Reputation:

Is a SqlConnection automatically closed when an application is closed?

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

Answers (3)

Steve Sheldon
Steve Sheldon

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

LarsTech
LarsTech

Reputation: 81675

If the application ends, the connection gets closed, along with everything else that was opened.

Upvotes: 0

Jon Skeet
Jon Skeet

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

Related Questions