Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
C#
public sealed class GetDBInstance
    {
        private static readonly object padlock = new object();
        private static DBCon _ObjInstance;

        public GetDBInstance() { }

        public static DBCon InstanceCon
        {

            get
            {
                if (_ObjInstance == null)
                {
                    lock (padlock)
                    {
                        if (_ObjInstance == null)
                            _ObjInstance = new DBCon();
                        _ObjInstance.strConnection = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

                    }
                }
                return _ObjInstance;
            }
        }
    }


C#
public class DBCon
    {
      public string strConnection { get; set; }
    }


using (SqlConnection connection = new SqlConnection(GetDBInstance.InstanceCon.strConnection))
Posted

1 solution

Drop your singleton and just use

using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) 


Using a singleton to return read-only config values doesn't make a lot of sense.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900