E
ed_p
Hello,
I have implemented the singleton pattern for a class to hold a
SqlConnection object that
will be used thruout the application to create commands. My application
is a simple Windows Form
Application that connects to a MSDE Database. I was reading the thread
yesterday on this very
same subject, but it only mentioned ASP.NET Applications. Can anyone
tell me if it's a good idea
to have one single SqlConnection Object in the application. Please note
that the Singleton Class
has been configured to be thread-safe. Below is some of the code I am
using to call the instance
of my Singleton class:
SqlCommand command = DB_Connection.Instance.Connection.CreateCommand();
Once I am done with the connection, I close it down:
command.Connection.Open();
//Do stuff here
command.Connection.Close();
I also dispose of the command object to make sure I free up resources.
Any information, suggestions, critiques
will be welcomed!
I have implemented the singleton pattern for a class to hold a
SqlConnection object that
will be used thruout the application to create commands. My application
is a simple Windows Form
Application that connects to a MSDE Database. I was reading the thread
yesterday on this very
same subject, but it only mentioned ASP.NET Applications. Can anyone
tell me if it's a good idea
to have one single SqlConnection Object in the application. Please note
that the Singleton Class
has been configured to be thread-safe. Below is some of the code I am
using to call the instance
of my Singleton class:
SqlCommand command = DB_Connection.Instance.Connection.CreateCommand();
Once I am done with the connection, I close it down:
command.Connection.Open();
//Do stuff here
command.Connection.Close();
I also dispose of the command object to make sure I free up resources.
Any information, suggestions, critiques
will be welcomed!