Is it necessary to dispose SqlConnection as well as SqlCommand?

后端 未结 2 1157
栀梦
栀梦 2021-01-24 22:49

Is it necessary to separately dispose of a SqlConnection as well as a SqlCommand?

I\'m doing some maintenance work on an application and found the following code:

<
2条回答
  •  走了就别回头了
    2021-01-24 23:13

    Yes, you will have to dispose (of) the connection separately. You can also see this in the source code: SqlCommand.Dispose() does not close or dispose the connection it uses (by the way, that would be bad anyway as you could not execute multiple commands with the same connection).

提交回复
热议问题