we can use statement using(sqlconnection con=new sqlconnection()) { }
no need to close the connection
Disconnected architecture means, you don’t need to connect always when you want to get data from the database. You do not need to open the connection explicitly. Once we fill data in dataset or datatable using fill method , the connection gets closed automatically.
if you dont use conobject.close() method connection will close (in disconnected architecture) if it sat idle for certain period of time automatically.
You must use: using ( SqlConnection oCnn = new SqlConnection()) {// your code here} // in the last line of the using the connection 'll be closed.If you do not close your connection, your Project will run slowly across multiple user scenarios.
use try{} ,catch{}, final{} ,or use "using{}"
con.disposed()
by the use of using block like using{}
Its depend on code if use DataAdapter then this will auto open and close on .fill command. In other case when you use conobj.open() and execute some query and do not close the connection then its depend on connection time out property.
No need to explicitly open and close the connection in disconnected architecture.
After completion of the main method.
finally{if (cn != null && cn.State == System.Data.ConnectionState.Open){cn.dispose();}}
You don't need to close the connection... It will automatic open and close the connection when needed.
once your connection is Open which is paramount then closing it should not be a necessity. because there are sometimes that you will even forget to close your connection and your code will still run. so its not compulsory