21
Reply

when connection will close in disconnected architecture if I dont use conobject.close() method?

Srikanth Reddy

Srikanth Reddy

7y
2.3k
0
Reply

    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.

    use try{} ,catch{}, final{} ,or use "using{}"

    con.disposed()

    Using

    Using block

    By using "using {}" block

    In using{}. Block

    by the use of using{} block

    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.

    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.

    we can use statement using(sqlconnection con=new sqlconnection()) { }

    we can use statement using(sqlconnection con=new sqlconnection()) { }

    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