/// <summary>
        /// Gets the instance.
        /// When class is first accessed, GetInsatnce() creates relevant object instance and returns object identity to programmer.
        /// On subsequent calls of getInstance(), no new instance is created, but identity of existing object is returned.
        /// </summary>
        /// <returns>return instance of DBProviderSingleton class</returns>
        public static DBProviderSingleton Instance(string connectionStringName)
        {
            try
            {
                if (objDBProviderSingleton == null)
                {
                    objDBProviderSingleton = new DBProviderSingleton(connectionStringName);
                }

                return(objDBProviderSingleton);
            }
            catch (Exception objEx)
            {
                throw new Exception("Error while creating instance of DBProviderSingleton.", objEx);
            }
        }
Beispiel #2
0
        private void Initialiger(string ConnectionStringName = "ConnectionString")
        {
            try
            {
                ////Executeting an instance of  DBProviderSingleton Class
                DBProviderSingleton objDBProviderSingleton = DBProviderSingleton.Instance(ConnectionStringName);

                string strProviderName = objDBProviderSingleton.ProviderName.Trim(); ////Assining ProviderName
                if (!string.IsNullOrEmpty(strProviderName))
                {
                    switch (strProviderName.Trim())
                    {
                    case "System.Data.SqlClient":
                        this.objDBProviderFactory = DbProviderFactories.GetFactory("System.Data.SqlClient");       ////Creating an instance of SQL
                        break;

                    case "System.Data.OleDb":
                        this.objDBProviderFactory = DbProviderFactories.GetFactory("System.Data.OleDb");       ////Creating an instance of OleDb
                        break;

                    case "System.Data.Odbc":
                        this.objDBProviderFactory = DbProviderFactories.GetFactory("System.Data.Odbc");        ////Creating an instance of Odbc
                        break;

                    case "System.Data.OracleClient":
                        this.objDBProviderFactory = DbProviderFactories.GetFactory("System.Data.OracleClient");         ////Creating an instance of Oracle
                        break;

                    default:
                        this.objDBProviderFactory = DbProviderFactories.GetFactory("System.Data.SqlClient");       ////Creating an instance of SQL
                        break;
                    }
                }

                this.objDBConnection = this.objDBProviderFactory.CreateConnection();                    ////It returns connection from DbProviderFactory.
                this.objDBCommand    = this.objDBProviderFactory.CreateCommand();                       ////Creating an instance from DbProviderFactory.
                this.objDBConnection.ConnectionString = objDBProviderSingleton.ConnectionString.Trim(); ////Assining Connection String
                this.objDBCommand.Connection          = this.objDBConnection;
            }
            catch (Exception objEx)
            {
                throw new Exception("Error on initializing connection.", objEx);
            }
        }
        /// <summary>
        /// Gets the instance.
        /// When class is first accessed, GetInsatnce() creates relevant object instance and returns object identity to programmer. 
        /// On subsequent calls of getInstance(), no new instance is created, but identity of existing object is returned.
        /// </summary>
        /// <returns>return instance of DBProviderSingleton class</returns>
        public static DBProviderSingleton Instance(string connectionStringName)
        {
            try
            {
                if (objDBProviderSingleton == null)
                {
                    objDBProviderSingleton = new DBProviderSingleton(connectionStringName);
                }

                return objDBProviderSingleton;
            }
            catch (Exception objEx)
            {
                throw new Exception("Error while creating instance of DBProviderSingleton.", objEx);
            }
        }