c# - Closing an OleDbConnection -


just general question, if open oledbconnection in program, should close @ point? ask because i've seen few tutorials presenter doesn't include statement close connection.

in specific circumstances, open connection access excel file, fill datatable , grab values. after though, there no reason me have connection open , i'm thinking cause issues if left open.

also, statement conn.close(); sufficient close connection?

yes, should close connection done it. if use connection in 1 method , not after again, close , dispose it, can cleaned up.

you should wrap creation of connection in using statement since close , dispose connection when exception occurs.

using (oledbconnection conn = new oledbconnection(...)) {     // use connection inside here } 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -