/// <summary> /// 获得新的数据库连接 /// </summary> /// <param name="connectionString">数据库连接字符串</param> /// <returns>数据库连接</returns> public virtual IDbConnection Open(string connectionString) { // 写入调试信息 #if (DEBUG) int milliStart = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif // 这里数据库连接打开的时候,就判断注册属性的有效性 if (!SecretUtil.CheckRegister()) { // 若没有进行注册,让程序无法打开数据库比较好。 connectionString = string.Empty; // 抛出异常信息显示给客户 throw new Exception(BaseSystemInfo.RegisterException); } // 若是空的话才打开 if (this.dbConnection == null || this.dbConnection.State == ConnectionState.Closed) { this.ConnectionString = connectionString; this.dbConnection = GetInstance().CreateConnection(); this.dbConnection.ConnectionString = this.ConnectionString; this.dbConnection.Open(); // 创建对象 // this.dbCommand = this.DbConnection.CreateCommand(); // this.dbCommand.Connection = this.dbConnection; // this.dbDataAdapter = this.dbProviderFactory.CreateDataAdapter(); // this.dbDataAdapter.SelectCommand = this.dbCommand; // 写入调试信息 #if (DEBUG) int milliEnd = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif } this.AutoOpenClose = false; return(this.dbConnection); }
/// <summary> /// 获得新的数据库连接 /// </summary> /// <param name="connectionString">数据库连接字符串</param> /// <returns>数据库连接</returns> public virtual IDbConnection Open(string connectionString) { // 这里数据库连接打开的时候,就判断注册属性的有效性 if (!SecretUtil.CheckRegister()) { // 若没有进行注册,让程序无法打开数据库比较好。 connectionString = string.Empty; // 抛出异常信息显示给客户 throw new Exception(BaseSystemInfo.RegisterException); } // 若是空的话才打开,不可以,每次应该打开新的数据库连接才对,这样才能保证不是一个数据库连接上执行的 this.ConnectionString = connectionString; this.dbConnection = GetInstance().CreateConnection(); this.dbConnection.ConnectionString = this.ConnectionString; this.dbConnection.Open(); this.MustCloseConnection = false; return(this.dbConnection); }