Normally I'm using the statements:
using (SqlConnection connection = new SqlConnection("Data ..."))
{
....
}
to define areas where I use sql commands. Now for a specific application I'm considering putting the sql connection into a singleton instead of the above construct:
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.....");
}
}
Now my question with this is....normally when I use "using" the connection gets closed,.... . But when I use a singleton it exists for the whole runtime of the program itself. Is it though necessary to make a "deconstructor" there in order to close the connection at the end of the program?