This is a follow up question to: Is it necessary to deconstruct singleton sql connections?
As a few comments there stated it is bad design to use a singleton for sql connection instead of doing multiple usings.
What intrigues me there though is one statement that the performance of the using variant is better than that of the singleton variant. Now as stated by me that it is a bad design is clear to me (I know most pros and cons for singletons there...especially the cons). What surprised me though was the performance statement.
As normally I would think: Ok opening and closing sql connections for 100-1000 times during a programs run SHOULD be less performant than doing this only once. Thus my question is: Is the performance of the non singleton variant really better and if so why?
Singletonexample:
public class SimpleClass
{
// Static variable that must be initialized at run time.
public static SqlConnection singletonConnection;
// Static constructor is called at most one time, before any
// instance constructor is invoked or member is accessed.
static SimpleClass()
{
singletonConnection = new SqlConnection("Data Source.....");
}
}
Usings example:
using (SqlConnection connection = new SqlConnection("Data ..."))
{
....
}