Is any connected dimension $0$ scheme affine? Let $X$ be a connected Scheme of dimension $0$. Is $X$ necessarily affine ? 
I know this is true if $X$ is Noetherian (even without assuming $X$ is connected). But what happens if $X$ is not Noetherian ?  
 A: Here is a counterexample.  Let $C$ be the Cantor set (or, any Stone space with no isolated points).  For each pair of distinct points $x,y\in C$, let $D_{xy}$ be the quotient of $C$ by the equivalence relation that identifies $x$ and $y$.  Let $U_{xy}=C\setminus\{x,y\}$ and let $V_{xy}$ be the image of $U_{xy}$ in $D_{xy}$.  Note that the quotient map $C\to D_{xy}$ restricts to a homeomorphism $U_{xy}\to V_{xy}$.
Now fix a field $k$, let $A$ be the ring of locally constant functions $C\to k$, and let $B_{xy}$ be the ring of locally constant functions $D_{xy}\to k$.  There is a natural homeomorphism $\operatorname{Spec} A\cong C$ sending a point of $A$ to the ideal of functions which vanish at it, and similarly $\operatorname{Spec} B_{xy}\cong D_{xy}$.  The quotient map $C\to D_{xy}$ induces a morphism $\operatorname{Spec} A\to \operatorname{Spec} B_{xy}$ which restricts to an isomorphism of schemes between $U_{xy}$ and $V_{xy}$, considered as open subschemes of $\operatorname{Spec} A$ and $\operatorname{Spec} B_{xy}$.   Now let $X$ be the scheme obtained by gluing together $\operatorname{Spec} A$ and $\operatorname{Spec} B_{xy}$ for all pairs $x,y$ along these isomorphisms between $U_{xy}$ and $V_{xy}$.  We will identify the copy of $\operatorname{Spec} A$ in $X$ with $C$ and the copy of $\operatorname{Spec} B_{xy}$ in $X$ with $D_{xy}$.
(If you have trouble visualizing this, it is analogous to the "line with doubled origin", except instead of "doubling" a single point of $C$, we have taken every pair of points in $C$ and "doubled" them but glued together their doubled versions.)
It is clear that $X$ is $0$-dimensional, since it is obtained by gluing together $0$-dimensional affine schemes.  Clearly $X$ is not affine (for instance, it is not quasicompact since it is obtained by gluing together infinitely many affine open sets, all of which are irredundant).  But I claim $X$ is connected.  Indeed, suppose $X=G\cup H$ is a nontrivial partition of $X$ into open sets.  Note that $C$ is dense in $X$ (since $V_{xy}$ is dense in $D_{xy}$ and has been identified with $U_{xy}\subset C$), so $G\cap C$ and $H\cap C$ are both nonempty.  Let $x\in G\cap C$ and $y\in H\cap C$.  Since $C$ has no isolated points and $G$ and $H$ are open, $x$ is not isolated in $G\cap C$ and $y$ is not isolated in $H\cap C$.  But this means $x$ is in the closure of $G\cap U_{xy}$ and $y$ is in the closure of $H\cap U_{xy}$.  It follows that the common image of $x$ and $y$ is in the closure of both $G\cap D_{xy}$ and $H\cap D_{xy}$, and thus is in both $G$ and $H$ since they are closed.  This is a contradiction since $G$ and $H$ were disjoint.

If this construction seems kind of ridiculous, note that any affine $0$-dimensional scheme is totally disconnected (see If $R$ is zero-dimensional, then $\mathrm{Spec}(R)$ is Hausdorff and totally disconnected).  So, to get a connected $0$-dimensional scheme with more than $1$ point, you have to somehow glue together a bunch of totally disconnected spaces along open sets to get a total space which is connected.  The idea of the construction above is to start with the Cantor set and then glue on pieces which kill all the open partitions $C=G\cup H$ by making the closures of $G$ and $H$ intersect in the pieces that were glued on.  Note that the non-Hausdorffness of the construction is crucial, since if our scheme were Hausdorff then all the clopen sets in any affine open would remain closed in the whole space by compactness.
