c# sql what to dispose

后端 未结 6 1255
南旧
南旧 2021-01-06 00:10

I have the code below to query records from a stored procedure but am concerned I may not be disposing what I need to or am disposing when the object would be cleared by the

6条回答
  •  南方客
    南方客 (楼主)
    2021-01-06 01:10

    you should open Connection firstly by Connection.Open(); then use the methods such as SqlDataReader to read after all,close SqlDataReader firstly and then close connection

    you can use keyword "using" to dispose it, but it is not a good idea

    in fact the keyword "using" is to dispose the object automatically. in other word,the object should achieve dispose method

提交回复
热议问题