예제 #1
0
 /// <summary>
 ///     打开连接
 /// </summary>
 /// <returns>是否打开,是则为此时打开,否则为之前已打开</returns>
 public bool Open()
 {
     if (_connection != null /* && _connection.State == ConnectionState.Open*/)
     {
         return(false);
     }
     _connection      = MySqlConnectionsManager.InitConnection(ConnectionStringName);
     IsLockConnection = true;
     return(true);
 }
예제 #2
0
 /// <summary>
 /// 析构
 /// </summary>
 public void Dispose()
 {
     if (IsDisposed)
     {
         return;
     }
     IsDisposed = true;
     if (!IsLockConnection)
     {
         MySqlConnectionsManager.Close(Connection, DataBase.ConnectionStringName);
     }
 }
예제 #3
0
 internal ConnectionScope(MySqlDataBase dataBase)
 {
     IsLockConnection = dataBase.IsLockConnection;
     DataBase         = dataBase;
     Transaction      = dataBase.Transaction;
     if (IsLockConnection)
     {
         Connection = dataBase._connection;
     }
     else
     {
         Connection = MySqlConnectionsManager.GetConnection(dataBase.ConnectionStringName);
     }
 }
예제 #4
0
        /// <summary>
        /// 执行与释放或重置非托管资源相关的应用程序定义的任务。
        /// </summary>
        public void Dispose()
        {
            if (_isDisposed)
            {
                return;
            }
            _isDisposed = true;
            DoDispose();

            if (_connection != null)
            {
                _connection      = null;
                IsLockConnection = false;
                if (Transaction != null)
                {
                    Transaction.Rollback();
                    Transaction = null;
                }
                MySqlConnectionsManager.Close(_connection, ConnectionStringName);
            }
        }
예제 #5
0
 /// <summary>
 /// 构造
 /// </summary>
 protected MySqlDataBase()
 {
     MySqlConnectionsManager.InternalInitialize();
     DependencyScope.DisposeFunc.Add(Dispose);
 }
예제 #6
0
        /// <summary>
        /// 初始化连接对象
        /// </summary>
        /// <returns></returns>
        private Task <MySqlConnection> InitConnectionAsync()
        {
            var connection = MySqlConnectionsManager.InitConnection(ConnectionStringName);

            return(Task.FromResult(connection));
        }