It's well known, that passing to modules of fractions is exact, i.e. if $$M'\xrightarrow{f} M\xrightarrow{g} M''$$ is an exact sequence of $A$-modules ($A$ being a commutative ring with unity), then for every multiplicative subset $S\subset A$, the induced sequence $$S^{-1}M'\to S^{-1}M\to S^{-1}M''$$ is exact.
But none of the books on commutative algebra I know treats whether for $M'\to M\to M''$ to be exact it suffices that $M'_\mathfrak{p}\to M_\mathfrak{p} \to M''_\mathfrak{p}$ is exact for each prime ideal $\mathfrak{p}\subset A$. So I was looking for a proof, even if I didn't expected it to be true (at least without some finiteness assumptions), and surprisingly it seems to work. But it's too easy to be right, though I can't find the error — so where am I mistaken? These are my thought:
Let $M'_\mathfrak{p}\to M_\mathfrak{p} \to M''_\mathfrak{p}$ be exact for each prime ideal $\mathfrak{p}\subset A$ (one could take maximal ideals as well). Then (only for the case this wasn't assumed anyway) we have $\operatorname{im}(f)\subset \ker(g)$, since for each prime $\mathfrak{p}\subset A$ we have $0=g_\mathfrak{p}\circ f_\mathfrak{p}(x) = (g\circ f)_\mathfrak{p}(x) = g\circ f (x)$ in $M''_\mathfrak{p}$ for all $x\in M'$, hence there exists $s\in A\setminus\mathfrak{p}$ such that $s\; (g\circ f(x))=0$. But with a standard argument (take $\mathfrak{p}\supset\operatorname{ann}(g\circ f(x))$ to produce a contradiction to the contrary) we get $g\circ f(x) = 0$ and $\operatorname{im}(f)\subset \ker(g)$.
Now we know, that the inclusion map $i\colon\operatorname{im}(f)\hookrightarrow \ker(g)$ is defined. But for each prime $\mathfrak{p}\subset A$ we assumed $i_\mathfrak{p}\colon \operatorname{im}(f_\mathfrak{p})\to\ker(g_\mathfrak{p})$ to be bijective and this is a local property, so $i\colon\operatorname{im}(f)\to \ker(g)$ is too and finally $\operatorname{im}(f)=\ker(g)$. Of cause this requires that localization commutes with $\ker$ and $\operatorname{im}$, but I'm sure this is true.
I'm getting more and more convinced it's right the more often I look at it but still, something bothers me. Any Suggestions or even counter examples?