internal void Connect( TimeSpan timeout ) { server.ClearInstances(); var exceptions = new List <Exception>(); foreach (var address in server.Settings.Servers) { try { var serverInstance = new MongoServerInstance(server, address); server.AddInstance(serverInstance); try { serverInstance.Connect(server.Settings.SlaveOk); // TODO: what about timeout? } catch { server.RemoveInstance(serverInstance); throw; } return; } catch (Exception ex) { exceptions.Add(ex); } } var innerException = exceptions.FirstOrDefault(); var connectionException = new MongoConnectionException("Unable to connect to server.", innerException); if (exceptions.Count > 1) { connectionException.Data.Add("exceptions", exceptions); } throw connectionException; }