dotnet / dotnet/dotnet-api-docs
IDisposable SqlCommand
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
I noticed that SqlCommand implements IDisposable (or rather DbCommand does and SqlCommand inherits from DbCommand), but in some instances in the docs I've seen SqlCommand is not wrapped in a using statement. Is there a reason for this? Maybe we are trusting SqlConnection to garbage collect the resources of SqlCommand?
Is it not a problem if SqlCommand isn't wrapped in a using? It seems I always see SqlConnection wrapped in a using; however, so I assume that's quite important.
Thanks.
---
#### Document Details
⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*
* ID: ee7dd835-d5dd-19e6-b044-1ed38f45289c
* Version Independent ID: 890a868d-fef0-0580-97b5-f29eb73df6c2
* Content: [SqlCommand Class (System.Data.SqlClient)](https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlcommand?f1url=https%3A%2F%2Fmsdn.microsoft.com%2Fquery%2Fdev15.query%3FappId%3DDev15IDEF1%26l%3DEN-US%26k%3Dk(System.Data.SqlClient.SqlCommand);k(DevLang-csharp)%26rd%3Dtrue&view=netframework-4.7.2)
* Content Source: [xml/System.Data.SqlClient/SqlCommand.xml](https://github.com/dotnet/dotnet-api-docs/blob/master/xml/System.Data.SqlClient/SqlCommand.xml)
* Product: **dotnet-api**
* GitHub Login: @douglaslMS
* Microsoft Alias: **douglasl**
Contributor guide
Assessment
This issue has not been assessed yet.