question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not Disposing SqlCommand or SqlDataReader on Caching.SqlServer

See original GitHub issue

Describe 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.

https://github.com/aspnet/Extensions/blob/f2ef1b55d65feac6ad4e3dd8b04daa21f464631b/src/Caching/SqlServer/src/DatabaseOperations.cs#L215-L227

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:

https://github.com/dotnet/corefx/blob/a53ada190e2e0bd229e76ae4a6d45c13a986ab18/src/System.Data.SqlClient/src/System/Data/SqlClient/SqlCommand.cs#L777-L785

https://github.com/dotnet/corefx/blob/a53ada190e2e0bd229e76ae4a6d45c13a986ab18/src/System.Data.SqlClient/src/System/Data/SqlClient/SqlDataReader.cs#L773-L793

Is there a particular reason why this is not done?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
epignosisxcommented, Feb 22, 2019

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.

1reaction
muratgcommented, Jan 22, 2019

@JunTaoLuo could you take a look please (the PR is linked.)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found