Skip to content

Instantly share code, notes, and snippets.

@iwouldnot
Created October 10, 2017 03:14
Show Gist options
  • Save iwouldnot/a6e4e9376f164209bf5f6b49d90bbb03 to your computer and use it in GitHub Desktop.
Save iwouldnot/a6e4e9376f164209bf5f6b49d90bbb03 to your computer and use it in GitHub Desktop.
singleton
public sealed class DBConnection
{
private static SqlConnection instance = null;
private static readonly object padlock = new object();
private DBConnection()
{
}
public static SqlConnection Instance
{
get
{
lock (padlock)
{
if (instance == null)
{
instance = new SqlConnection(conStr);
}
return instance;
}
}
}
public static void Open()
{
if (instance != null)
instance.Open();
}
public static void Close()
{
if (instance != null)
instance.Close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment