public async Task VerifyConnectivityAsync() { // As long as there is a fresh routing table, we consider we can route to these servers. try { await _routingTableManager.EnsureRoutingTableForModeAsync(Simple.Mode, Simple.Database, Simple.Bookmark); } catch (ServiceUnavailableException e) { throw new ServiceUnavailableException( "Unable to connect to database, " + "ensure the database is running and that there is a working network connection to it.", e); } }
public async Task VerifyConnectivityAsync() { // As long as there is a fresh routing table, we consider we can route to these servers. try { var database = await SupportsMultiDbAsync().ConfigureAwait(false) ? "system" : null; await _routingTableManager.EnsureRoutingTableForModeAsync(Simple.Mode, database, Simple.Bookmark).ConfigureAwait(false); } catch (ServiceUnavailableException e) { throw new ServiceUnavailableException( "Unable to connect to database, " + "ensure the database is running and that there is a working network connection to it.", e); } }
public async Task <IConnection> AcquireConnectionAsync(AccessMode mode) { await _routingTableManager.EnsureRoutingTableForModeAsync(mode).ConfigureAwait(false); while (true) { Uri uri; switch (mode) { case AccessMode.Read: uri = _loadBalancingStrategy.SelectReader(_routingTableManager.RoutingTable.Readers); break; case AccessMode.Write: uri = _loadBalancingStrategy.SelectWriter(_routingTableManager.RoutingTable.Writers); break; default: throw new InvalidOperationException($"Unknown access mode {mode}"); } if (uri == null) { // no server known to routingTable break; } IConnection conn = await CreateClusterConnectionAsync(uri, mode).ConfigureAwait(false); if (conn != null) { return(conn); } //else connection already removed by clusterConnection onError method } throw new SessionExpiredException($"Failed to connect to any {mode.ToString().ToLower()} server."); }