.net - Close and Dispose - which to call? -
having read threads is sqlcommand.dispose enough? , closing , disposing wcf service wondering classes such sqlconnection or 1 of several classes inheriting stream class matter if close dispose rather close?
i want clarify situation.
according microsoft guidelines, it's practice provide close method suitable. here citation framework design guidelines
consider providing method
close(), in additiondispose(), if close standard terminology in area. when doing so, important makecloseimplementation identicaldispose...
in of cases close , dispose methods equivalent. main difference between close , dispose in case of sqlconnectionobject is:
an application can call
closemore 1 time. no exception generated.if called
disposemethodsqlconnectionobject state reset. if try call method on disposedsqlconnectionobject, receive exception.
that said:
- if use connection object 1 time, use
dispose. - if connection object must reused, use
closemethod.
Comments
Post a Comment