Suppose $X$ is a projective variety over $\mathbb C$. I am happy to entertain more or different adjectives — I'm not looking for the most general statement, but rather to understand when and how smooth-manifold intuition leads me astray. I know very little algebraic geometry, and so please forgive and correct me if a statement below is mistaken.


It is rare for a line bundle $\mathcal L \to X$ to have a nowhere-vanishing section, and when it does, there are usually very few (only $\mathbb C^\times$ many).
Suppose instead that I ask for a weaker structure than for $\mathcal L$ to have a section, but rather let me ask only that it has a flat connection. My question is:



> 
> In algebraic geometry, how often does a line bundle have a flat connection? When it has a flat connection, how many flat connections can it have?
> 
> 
> 



How many flat connections has a line bundle in algebraic geometry?
I presume that your variety $X$ is smooth.


Consider the additive map $\mathrm d\log \colon \mathscr O\_X^\*\to \Omega^1\_X$ that sends $f$ to $\mathrm df/f$. It induces a map $c\_1$ in cohomology from $H^1(X,\mathscr O\_X^\*)$
to $H^1(X,\Omega^1\_X)$ — a coherent avatar of the first Chern class.
By Hodge Theory, $H^1(X,\Omega^1\_X)$ is a subspace of $H^2(X,\mathbf C)$ and the two notions
of first Chern class coincide. 


A line bundle $\mathscr L$ has a connection if and only if its first Chern class $c\_1(\mathscr L)\in H^1(X,\Omega^1\_X)$ vanishes. The proof is straightforward: take an open cover $(U\_i)$ of $X$, an invertible section $s\_i$ of $\mathscr L$ on $U\_i$ and the associated cocycle $(f\_{ij})$ representing your line bundle in $H^1(X,\mathscr O\_X^\*)$. A connection $\nabla$ maps $s\_i$ to $s\_i\otimes\omega\_i$, for some 1-form $\omega\_i\in H^0(U\_i,\Omega^1\_X)$. The condition that these $s\_i\otimes\omega\_i$ come from a global connection on $X$ is exactly the vanishing of $c\_1(\mathscr L)$.


It is a non-trivial fact that if $\mathscr L$ has an algebraic connection, then it is automatically flat. Torsten Ekedahl gave an algebraic proof on [this thread of MO](https://mathoverflow.net/questions/80280/line-bundles-with-integrable-connection-on-abelian-varieties)
(Ekedahl also observes that $p$th power of line bundles in characteristic $p$ have an integrable connection), but an analytic proof seems easy. The algebraic connexion $\nabla$ gives rise to a connexion $\nabla+\bar\partial$ on the associated holomorphic line bundle. One checks that the curvature of this connection is a $(2,0)$-form, while it should be a $(1,1)$-form. Consequently, it vanishes. 


When non empty, the set of flat connections on a vector bundle $\mathscr E$ is an affine space under $H^0(X,\Omega^1\_X\otimes\mathscr E\mathit{nd}(\mathscr E))$, a finite dimensional vector space. In our case, $\mathscr L$ is a line bundle, hence $\mathscr E\mathit{nd}(\mathscr L)$ is the trivial line bundle so that we get $H^0(X,\Omega^1\_X)$.


NB. Following the comment of Ben McKay, I edited the last paragraph.


