Spectrum of $\mathcal{O}(U)$ Let $X=\operatorname{Spec}(A)$ be the spectrum of the comm. ring $A$ and let $\mathcal{O}$ be the associated sheaf of rings, i.e. for $U \subseteq X$ open, $\mathcal{O}(U)$ is the ring of all functions $s: U \to \prod_{p \in U}A_p$ such that for all $p \in U$ there is an open neigbourhood $V \subseteq U$ of $p$ and there are $a \in A, f \in A \setminus \bigcup_{q \in V}q$ with $s(q) = a/f$ for all $q \in V$. 
Question: What is $\operatorname{Spec}\mathcal{O}(U)$ ? 
There are two special cases for $U$ that are easy to handle: 
(1) We have $\mathcal{O}(X)=A$ and thus $\operatorname{Spec}\mathcal{O}(U)(X)=X$. 
(2) For a principal open subset $D(f),\, \,\mathcal{O}(D(f))=A_f$ and thus $\operatorname{Spec}\mathcal{O}(D(f))=D(f)$. 
Therefore I suppose $\operatorname{Spec}\mathcal{O}(U)=U$. I found the map $$U \to \operatorname{Spec}\mathcal{O}(U),\, q \mapsto \mathcal{O}(U) \cap \prod_{p \in U} B_p$$ where $B_p: =A_p$ for $p \neq q$ and $B_q := qA_q$. But I'm not able to show that it is surjective. 
Any hint or reference is appreciated. Please note that the question is no homework, but an attempt to get a better understanding of the ring $\mathcal{O}(U)$. 
 A: Quite generally there exists for a completely arbitrary scheme $Y$ a canonical morphism of schemes $$j:Y\to \operatorname{Spec} \mathcal O(Y)$$ sending the point $y\in Y$ to the prime ideal $j(y)\subset \mathcal O(Y)$ consisting of those global functions $f\in \mathcal O(Y)$ vanishing at $y$ [which means that $f_y\in \mathfrak m_y\subset\mathcal O_{Y,y}$ where $\mathfrak m_y$ is the maximal ideal of the local ring $\mathcal O_{Y,y}$].
The key point is that $j$ is an isomorphism of schemes if and only if $Y$ is affine.  
This can now be applied to your open subset $U\subset X=\operatorname{Spec} A$, thus obtaining the morphism $j:U\to \operatorname{Spec} \mathcal O(U)$.
This morphism will be an isomorphism iff $U$ is itself affine.
In general $j$ is only an open immersion: this is  Lemma 27.15.4 in De Jong and collaborators' Stacks Project.
However  $j$ needn't be surjective: a counterexample is obtained (as mentioned by Bruno in his comment to the question) by taking  $X=\mathbb A^2_k=\operatorname{Spec}k[T_1,T_2]$ and $U=\mathbb A^2_k\setminus \{(0,0)\}$.
We have $\mathcal O(U)=k[T_1,T_2]$   and $j$ is the open immersion  $$j:U=\mathbb A^2_k\setminus \{(0,0)\}\hookrightarrow \operatorname{Spec} \mathcal O(U)=\operatorname{Spec}k[T_1,T_2]=\mathbb A^2_k$$ whose image misses the origin $\{(0,0)\}$.
A: Just to add to Georges' answer, this map 
$$
j: Y \to \operatorname{Spec}\mathcal{O}(Y)
$$
is universal with respect to maps to affine space. That is, for any morphism $\varphi: Y \to \operatorname{Spec}A$, there is a unique morphism $\tilde{\varphi}: \operatorname{Spec}\mathcal{O}(Y) \to \operatorname{Spec}A$ such that the $\varphi = \tilde{\varphi}\circ j$. This follows from the natural isomorphism $\operatorname{Hom}_{Sch}(X, \operatorname{Spec}A) = \operatorname{Hom}_{CommRing}(A, \mathcal{O}(X))$. So in some sense $\operatorname{Spec}\mathcal{O}(Y)$ is the closest affine scheme to $Y$. 
