= Solution
An <open immersion> $j:U\to X$ is a <morphism of schemes> that identifies $U$, including its <structure sheaf of a scheme>[structure sheaf], with an open subscheme of $X$.
Let $X=\mathbb A_k^2$ and $U=X\setminus\{(0,0)\}$. The inclusion is an open immersion and $X$ is an <affine scheme>, but $U$ is not affine. Indeed, regular functions extend across the missing codimension-two point, so
$$
\Gamma(U,\mathcal O_U)=k[x,y]=\Gamma(X,\mathcal O_X).
$$
Were $U$ affine, the inclusion would therefore correspond to an isomorphism of coordinate rings and would be an isomorphism $U\cong X$, a contradiction.
For an example with both schemes affine, the <principal open subscheme>
$$
D(t)=\operatorname{Spec}k[t,t^{-1}]\hookrightarrow\operatorname{Spec}k[t]=\mathbb A_k^1
$$
is a nontrivial open immersion. The affine line is connected because $k[t]$ has no nontrivial <idempotent>[idempotent elements].
Back to article page