/// <summary> /// 打开连接 /// </summary> /// <returns>是否打开,是则为此时打开,否则为之前已打开</returns> public bool Open() { if (_connection != null /* && _connection.State == ConnectionState.Open*/) { return(false); } _connection = MySqlConnectionsManager.InitConnection(ConnectionStringName); IsLockConnection = true; return(true); }
/// <summary> /// 析构 /// </summary> public void Dispose() { if (IsDisposed) { return; } IsDisposed = true; if (!IsLockConnection) { MySqlConnectionsManager.Close(Connection, DataBase.ConnectionStringName); } }
internal ConnectionScope(MySqlDataBase dataBase) { IsLockConnection = dataBase.IsLockConnection; DataBase = dataBase; Transaction = dataBase.Transaction; if (IsLockConnection) { Connection = dataBase._connection; } else { Connection = MySqlConnectionsManager.GetConnection(dataBase.ConnectionStringName); } }
/// <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); } }
/// <summary> /// 构造 /// </summary> protected MySqlDataBase() { MySqlConnectionsManager.InternalInitialize(); DependencyScope.DisposeFunc.Add(Dispose); }
/// <summary> /// 初始化连接对象 /// </summary> /// <returns></returns> private Task <MySqlConnection> InitConnectionAsync() { var connection = MySqlConnectionsManager.InitConnection(ConnectionStringName); return(Task.FromResult(connection)); }