A slightly closer-to-the-ground solution to this problem.
Proposition: Let $L \to N \to P$ be a sequence of $A$-modules, where $A$ is a commutative unital ring. Then the following two are equivalent:
- The sequence $L\to N\to P$ is exact
- For every maximal ideal $m$ of $A$, the sequence $L_m \to N_m \to P_m$ is exact.
Proof: That 1 implies 2 follows immediately from that, for any multiplicative set $S$, the mapping $M$ to $S^{-1}M$ of $A$-modules to $S^{-1}A$-modules is an exact functor.
So, we prove that 2 implies 1. Let $f: L\to N$ be the first arrow and $g: N\to P$ be the second arrow.
Part one: $\mathrm{Im}(f)\subseteq \mathrm{ker}(g)$
Take an arbitrary $\ell\in L$ and let $\mathrm{Ann}(g(f(l))) = \{x\in A: xg(f(l)) = 0\}$. This is clearly an ideal, and it is the entire ring iff $g(f(l))=0$. So, suppose for contradiction that $\mathrm{Ann}(g(f(l)))\neq 0$, so there exists some maximal ideal $m\supset\mathrm{Ann}(g(f(l)))$. By hypothesis, we now have that the sequence
$$L_m \to N_m\to P_m$$
is exact. So $g_m(f_m(\frac{l}{1}))=\frac{0}{1}$ in $P_m$, giving $\frac{g(f(l))}{1}=\frac{0}{1}$ in $P_m$.
That is, there exists some $u\in A\setminus m$ such that $u g(f(l))=0$. But this is a contradiction, since any such $u$ lies in $\mathrm{Ann}(g(f(l)))$ and thus in $m$, not in its complement.
Part two: $\mathrm{ker}(g) \subset \mathrm{im}(f)$
Let $n\in \mathrm{ker}(g)$, and let $I= \{x\in A: xn \in \mathrm{im}(f)\}$, which can easily be verified to be an ideal (since $\mathrm{im}(f)$ is a submodule). Now obviously $I=A$ iff $n\in \mathrm{im}(f)$. So suppose for contradiction that $I\neq A$, so that there exists a maximal ideal $m$ in $A$ containing $I$.
Again, we have by hypothesis that the sequence
$$L_m \to N_m\to P_m$$
is exact. Thus, since $\frac{n}{1}\in\mathrm{ker}(g_m)$, there exists an $\frac{l}{s}\in L_m$ such that $f_m(\frac{l}{s})=\frac{n}{1}$ in $N_m$. This equality gives us that there exists a $u\in A\setminus m$ such that
$$u(f(l)-ns) = 0 \Leftrightarrow f(ul) = usn$$
so that $usn\in \mathrm{Im}(f)$. Now, by definition of $I$, this implies $us\in I$. But $us \in A\setminus m$ too, which gives our contradiction. ∎