I'm a big fan of nested using statments to implement your option 1 for each of your Select, Insert, Update, Delete, etc. methods. Like:
Code:
public static SomeList GetSomeList()
{
...
using (SqlConnection connection = new SqlConnection(AppConfiguration.ConnectionString))
{
connection.Open();
using (SqlCommand command = connection.CreateCommand())
{
// Initialize command
using (SqlDataReader reader = command.ExecuteReader())
{
/// Load collection
}
}
}
return collection;
}
etc., etc....
That way your IDisposable objects (like your connection object) will be disposed automatically when the using statment exits.
Using statemens actually compile to:
Code:
try
{
SqlConnection connection = new SqlConnection(AppConfiguration.ConnectionString)
connection.Open();
}
finally
{
if (connection != null)
((IDisposable)connection).Dispose();
}
So connection.Dispose gets called even if an exception occurs. Module level connection objects are old school. Check out MSDN on using statments.
HTH,
Bob