© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
5 replies
shuu

✅ the best way to clean up SqlConnection

Hey guys, basically i want to clean up the sql connection after done with querying stuff on each request, i put it in using block but i notice that the connection instance (SqlConnection) still there after gone out of the using scope, it looks like Garbage Collector doesn't clean them immediately. When i check how many active connection to my database, just a small amount of them like 3 or 4, but when i check it in Rider, there was like hundred of them allocated in memory, i guess they aren't cleaned up but rather than they are being deactived and remain there waiting for the Garbage Collector to clean up, so basically i want to explicity do it myself, what is the best practice here ? Thanks for reading
image.png
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

The best way to handle Errors in Clean Arch
C#CC# / help
3y ago
✅ SQLConnection and queries to the database
C#CC# / help
3y ago
SqlConnection Connection Disposed
C#CC# / help
15mo ago
SqlConnection not defined?
C#CC# / help
3y ago