Skip to content

Instantly share code, notes, and snippets.

@hagbarddenstore
Last active December 10, 2015 15:28
Show Gist options
  • Select an option

  • Save hagbarddenstore/4454278 to your computer and use it in GitHub Desktop.

Select an option

Save hagbarddenstore/4454278 to your computer and use it in GitHub Desktop.
A simple example that shows the principle of opening late and closing early.
public void TheWrongWay()
{
var connection = new SqlConnection(...);
connection.Open();
DoSomethingTimeConsumingThatDoesNotUseTheDatabase();
// execute query
connection.Close();
}
public void TheRightWay()
{
var connection = new SqlConnection(...);
DoSomethingTimeConsumingThatDoesNotUseTheDatabase();
connection.Open();
// execute query
connection.Close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment