Last post Nov 07, 2009 12:34 PM by TATWORTH
Nov 02, 2009 03:04 PM|aspfun|LINK
I used code below to close connection, is it right?
Catch ex As Exception
'code to display error message
Does it need " mySQLCommand.Dispose()"?
Nov 02, 2009 03:11 PM|crawford.r|LINK
That should work fine; but it is doing some extra work. myConn.Dispose() will automatically call myConn.Close(), so myConn.Close() is not needed. As for mySQLCommand.Dispose(), it isn't absolutely necessary, but it's probably a good idea to keep it.
Nov 02, 2009 03:19 PM|budugu|LINK
Even better..It saves you the hassle of manually creating the try / finally block and calling Dispose().
Using cn As New SqlConnection(myConn)
Using cm As New SqlCommand(mySQLCommand, cn)
Nov 07, 2009 12:34 PM|TATWORTH|LINK
>Does it need " mySQLCommand.Dispose()"?
One way of finding out is to run FXCOP with and wiithout the line commented out. You can get FXCOP from