Solution 1:

The Euler class detects topological triviality, not triviality in the finer sense of whether or not a flat connection is a product.

The prototypical example of a flat, non-trivial bundle starts with the product bundle $[0, 1] \times U(1) \to [0, 1]$ equipped with the product connection. If $\theta$ is an arbitrary real number, glue the fibre over $0$ to the fibre over $1$ by rotating through $\theta$; that is, identify $(0, e^{i\phi}) \sim (1, e^{i(\phi + \theta)})$.

The result is a flat, topologically-trivial $U(1)$ bundle $P \to S^{1}$ over the circle. If $\theta \not\in 2\pi \mathbf{Z}$, however, then $P$ admits no covariantly-constant section. When an arbitrary point of $S^{1}$ is removed, the restriction of $P$ to the resulting open interval $I$ is a product bundle $I \times U(1)$ whose covariantly-constant sections are constant maps $I \to U(1)$, and no such section extends continously to a global section of $P$.

In case it's of interest, there similarly exist topologically-trivial holomorphic line bundles over an elliptic curve $E$ that admit no non-trivial global section. For example, let $p$ and $q$ be distinct points of $E$, and let $L$ be the line bundle associated to the divisor $[p] - [q]$. A non-trivial holomorphic section of $L$ would define a meromorphic function $f$ on $E$, holomorphic off $q$ and with a simple zero at $p$ and a simple pole at $q$. Integrating the meromorphic $1$-form $$ \eta = z \frac{f'(z)\, dz}{f(z)} $$ around the boundary of a fundamental domain for $E$ and using the fact that the total residue is zero would give $p - q = 0$, which is not the case.

Solution 2:

This is an answer to your question 1); question 2) is covered in Andrew's answer.

You're mistaking two different characteristic classes. There's the integral first Chern class $c_1(E) \in H^2(M,\Bbb Z)$ and the real first Chern class $c_{1,dR}(E) \in H^2_{dR}(M)$. This last one is the one you calculate with Chern-Weil theory. They're usually not denoted differently. The relation is that, under the canonical map (changing coefficients and then following the de Rham isomorphism), $c_1(E) \mapsto c_{1,dR}(E)$.

Having a flat connection on a $U(1)$-bundle is equivalent to $c_{1,dR}(E)$ vanishing. You've proved one direction. In the other direction, suppose it vanishes, and that $A$ is a connection on your bundle. I want to find a 1-form $a \in \Omega^1(E \otimes E*) \cong \Omega^1(M)$ such that $da = - F_A$, because of the equation $F_{A+a} = F_A + da$ for connections on a $U(1)$-bundle. Now note that the right hand side is closed by the Bianchi identity; and by your assumption that $c_{1,dR}(E)$ is zero, we see that it must actually be exact. So I can find such an $a$, and therefore my bundle is flat iff $c_{1,dR}(E)$ is torsion.

What's the difference? Torsion classes! Since $M$ is compact we can decompose its second cohomology as $H^2(M;\Bbb Z) \cong \Bbb Z^a \oplus T$, where $T$ is a finite group. That finite group is the group of flat $U(1)$-bundles up to bundle isomorphism, not necessarily preserving the flat connection, because their real first Chern classes vanish.

Solution 3:

Topological line bundles are classified by $H^1(X, U(1)) \cong H^2(X, \mathbb{Z})$ where $U(1)$ has the usual topology. Flat line bundles are classified by $H^1(X, U(1)) \cong \text{Hom}(H_1(X), U(1))$ where $U(1)$ has the discrete topology; this is often denoted by $U(1)_d$. There's a natural map

$$H^1(X, U(1)_d) \to H^1(X, U(1)) \cong H^2(X, \mathbb{Z})$$

sending a flat line bundle to its first Chern class, and Chern-Weil theory implies that if $X$ is a smooth manifold then this class has image zero in de Rham cohomology. But as Mike Miller says this only implies that it's torsion, not zero.