I would advise to use
lazy initialization pattern () to open a connection when required and keep it open. Something like this:
class DatabaseWrapper {
internal DatabaseWrapper() {
fConnection = new
}
Connection Connection {
get {
if (fConnection.State != System.Data.ConnectionState.Open)
fConnection.Open();
return fConnection;
}
}
SomeMethod() {
Command command = new Command(query, Connection);
}
Connection fConnection;
}
—SA