Details about specific commands to close SQLConnection class
Posted on 2013-01-10
I need a little help for a question connected with Net3.5 SQLConnection class. When I finish usages of SQLDataReader and SQLConnection I know that I should release the recourses, my question is for detail command I should use.
I have 2 SQLDataReaders and 1 SQLConnection – now I use a code like this
readerCamp.Dispose(); reader.Dispose(); conn.Dispose();
The right questions I have are:
1. Do I really need to close SQLDataReaders, or just conn.Dispose is enogh because it will close on himself all relative connection /SQLDataReaders which used it/
2. The command conn.Dispose(); is equal to conn=null; - true or not?
3. Long time I use code like:
if (conn.State != ConnectionState.Closed) conn.Close();
is that necessary? If the result is same prefer use just conn.Dispose();