/// <summary>
        /// 获得新的数据库连接
        /// </summary>
        /// <param name="connectionString">数据库连接字符串</param>
        /// <returns>数据库连接</returns>
        public virtual IDbConnection Open(string connectionString)
        {
            // 这里数据库连接打开的时候,就判断注册属性的有效性
            if (!SecretHelper.CheckRegister())
            {
                // 若没有进行注册,让程序无法打开数据库比较好。
                connectionString = string.Empty;
                // 抛出异常信息显示给客户
                throw new Exception(SystemInfo.RegisterException);
            }

            this.ConnectionString = connectionString;
            this.dbConnection     = GetInstance().CreateConnection();
            this.dbConnection.ConnectionString = this.ConnectionString;
            this.dbConnection.Open();
            this.AutoOpenClose = false;

            return(this.dbConnection);
        }
Esempio n. 2
0
        public virtual IDbConnection Open(string connectionString)
        {
            int tickCount = Environment.TickCount;

            Trace.WriteLine(DateTime.Now.ToString(SystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
            if (!SecretHelper.CheckRegister())
            {
                connectionString = string.Empty;
                throw new Exception(SystemInfo.RegisterException);
            }
            if ((this.dbConnection_0 == null) || (this.dbConnection_0.State == ConnectionState.Closed))
            {
                this.ConnectionString = connectionString;
                this.dbConnection_0   = this.GetInstance().CreateConnection();
                this.dbConnection_0.ConnectionString = this.ConnectionString;
                this.dbConnection_0.Open();
                int num2 = Environment.TickCount;
                Trace.WriteLine(DateTime.Now.ToString(SystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds((double)(num2 - tickCount)).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
            }
            return(this.dbConnection_0);
        }