/// <summary> /// Close the database connection /// </summary> /// <returns></returns> public async Task CloseAsync() { // it might sound silly // but if we are connecting, we need to wait a little. // so we don't disconnect ... while connecting. await WaitIfConnectingAsync().ConfigureAwait(false); // are we open? ThrowIfNotOpen(); try { // rollback open transaction RollbackOpenTransactions(); // close the worker. if (_worker != null) { await _worker.CloseAsync().ConfigureAwait(false); } // disconnect everything _connectionBuilder.Disconnect(); } finally { _connectionState = ConnectionState.Closed; } }
private async Task OpenErrorAsync() { _connectionBuilder?.Disconnect(); if (_worker != null) { await _worker.CloseAsync().ConfigureAwait(false); _worker = null; } _connectionState = ConnectionState.Broken; }