An example
Consider any representation $\varrho$ of $\pi_1(S)$ into $\mathbb C^\ast$. The representation $\varrho \times \varrho^{-1}$ can be though as representation on $SL(2,\mathbb C)$. Any connection realizing this representation leave two line bundles invariant. These lines bundles are determined by the image of $\varrho$ and $\varrho^{-1}$ into $H^1(S, {\mathcal O^{\ast}}_S)$ by the natural morphism $$ Hom(\pi_1(S), \mathbb C^{\ast}) \to H^1(S, \mathbb C^{\ast}) \to H^1(S,{\mathcal O_S}^{\ast}) $$
Thus in this case the representation determines the line-bundle, and it must be of the form $\mathcal L \oplus \mathcal L^*$. Of course the line-bundle $\mathcal L$ may be trivial for some complex structures but not for others. But if we start with a non-trivial representation with values in $S^1\subset \mathbb C^{\ast}$ then the line-bundle will not be trivial in not matter which complex structure since $H^1(S,S^1)$ is naturally isomorphic to $\ker H^1(S,\mathcal O_S^{\ast}) \to H^2(S, \mathbb Z)$.
Hilbert's 21st Problem
Your question is related to Hilbert's 21st problem. In it, instead of considering a compact Riemann surface of genus $g$ with a holomorphic connection on the trivial bundle one considers $\mathbb P^1$ minus a finite set $\Gamma$ of points with a meromorphic connection on the trivial bunle with at most simples poles on $\Gamma$.
It is known that every representation of $\pi_1(\mathbb P^1 - \Gamma)$ on $SL(2,\mathbb C)$ is realized by a meromorphic connection on the trivial bundle with simple poles on $\Gamma$. I believe that this result is due to Birkhoff
In Hilbert's 21st problem a parameter counting does not suffices to exclude the other groups $SL(n,\mathbb C)$, $n \ge 3$. Indeed Bolibruch proved that irreducible representations are always realizable, and constructed counter examples for the general case starting with dimension $n \ge 3$ if I remember correctly. Moreover, there are examples which show that the answer may depend on the analytic invariants of the set $\Gamma$.

