Not Disposing SqlCommand or SqlDataReader on Caching.SqlServer
See original GitHub issueDescribe the bug
We are being hit at least weekly with this issue filed in corefx.
Going through the source code of the Caching.SqlServer package I notice that some classes that implement IDisposable
are not wrapped in a using
block.
In this snippet both SqlCommand
and the SqlDataReader
implement IDisposable
but they are not disposed, and looking at their implementation it looks like they are actually doing some clean up work:
Is there a particular reason why this is not done?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
SqlCommand.Dispose() not disposing the SqlParameters in it
I see this: i properly dispose everything. and this: I've disposed sqlcommand object by calling oSqlCommand.Dispose().
Read more >SqlCommand.Dispose doesn't free managed object #74
The cached metadata is kept in case it is needed for faster reading of further rows from a returned datareader. In the case...
Read more >Retrieving Data Using a DataReader - ADO.NET
The DataReader is a good choice when you're retrieving large amounts of data because the data is not cached in memory.
Read more >SqlDataReader.Close Method (Microsoft.Data.SqlClient)
The Close method may either be called directly or through the Dispose method, disposing directly or in the context of the using statement...
Read more >ADO.NET Interview Questions And Answers
Question 5: What is the differences Between DataReader and DataSet? Answer. No, DataReader, DataSet. 1, Used in a connected architecture, Used ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I submitted a PR that was merged, but it will not be available until 3.0.
The truth is I don’t know if this fix will actually resolve the issues we’ve been having in production.
Also, the fact that no one else have reported this makes it look it’s a problem on my side, rather than the framework, but at the same time we interact with other DBs and we have not run into this problem (following the recommendation of disposing of all ADO.NET objects).
I would really like to hear from you if this issue comes up. Maybe then, @tratcher will consider it for a servicing release.
I’m going to close this issue because the PR was accepted.
@JunTaoLuo could you take a look please (the PR is linked.)