I am creating a Microsoft Web API backend that connects to an Oracle database. Which is the best way to manage the DB connection: open the database connection once and access it through a static class / method, or open a DB connection each time I need to query the DB and close it again?
Right now I'm using the static connection:
public static class DbConnConfig {
public static string ConnString = "Provider=OraOLEDB.Oracle; ... otherstuff ...";
public static OleDbConnection conn = null;
public static OleDbConnection getConnection() {
if(DbConnConfi.conn==null) {
conn = new OleDbConnection(ConnString);
conn.Open();
}
return conn;
}
}
... and then in any class that needs the connection I call DbConnConfig.getConnection()