Calculating the integral $\int\limits_{0}^{2\pi} \frac{d \theta}{a^2 \sin^2\theta+b^2 \cos^2\theta}$ I wanted to calculate $$\int\limits_{0}^{2\pi} \frac{d \theta}{a^2 \sin^2\theta+b^2 \cos^2\theta}$$
So I solved the indefinite integral first (by substitution):
$$\int\frac{d \theta}{a^2 \sin^2\theta+b^2 \cos^2\theta}=\frac{1}{b^2}\int\frac{d \theta}{\cos^2\theta \left(\frac{a^2}{b^2} \tan^2\theta+1 \right)} =\left[u=\frac{a}{b}\tan\theta, du=\frac{a}{b\cos^2\theta} d\theta \right ]\\=\frac{1}{b^2}\int\frac{b}{a\left(u^2+1 \right)}du=\frac{1}{ab}\int\frac{du}{u^2+1}=\frac{1}{ab} \arctan \left(\frac{a}{b}\tan\theta \right )+C$$
Then:
$$\int\limits_{0}^{2\pi} \frac{d \theta}{a^2 \sin^2\theta+b^2 \cos^2\theta}=\frac{1}{ab} \arctan \left(\frac{a}{b}\tan (2\pi) \right )-\frac{1}{ab} \arctan \left(\frac{a}{b}\tan 0 \right )=0$$
Which is incorrect (the answer should be $2\pi/ab$ for $a>0,b>0$).
On the one hand, the substitution is correct, as well as the indefinite integral itself (according to Wolfram it is indeed $\frac{1}{ab} \arctan \left(\frac{a}{b}\tan\theta \right )$  ), but on the other hand I can see that had I put the limits during the substitution I'd get $\int\limits_{0}^{0} \dots = 0$ because for $\theta = 0 \to u=0$ and for $\theta = 2\pi \to u=0$.
Why is there a problem and how can I get the correct answer?
Edit: Here is Wolfram's answer:


Wolfram is correct because $$\frac{a^2 b^2}{2}\int\limits_{0}^{2\pi} \frac{d \theta}{a^2 \sin^2\theta+b^2 \cos^2\theta}$$ is the area of an ellipse (defined by $x=a\cos t , y=b\sin t$), that is $$\frac{a^2 b^2}{2}\int\limits_{0}^{2\pi} \frac{d \theta}{a^2 \sin^2\theta+b^2 \cos^2\theta}=\pi ab$$

A slick way to compute this considers the closed loop $\gamma(t) = a\sin t + i b\cos t$ given by the ellipse and traversed clockwise. Then
$$\frac 1{2\pi i}\int_\gamma\frac{dw}w = -1$$
independently of $a$ and $b$ (this is computing the number of turns the ellipse makes around $w=0$, which is $-1$). On the other hand, computing the line integral explicitly gives
\begin{align}
\frac{1}{2\pi i}\int_0^{2\pi }\frac{\overline{\gamma(t)}}{|\gamma(t)|^2} \gamma'(t)dt &=  \frac{1}{2\pi i}\int_0^{2\pi }\frac{a\sin t - i b\cos t}{a^2\sin^2 t + b^2\cos^2 t} (a\cos t - i b\sin t)dt \\
&=  \frac{1}{2\pi i}\int_0^{2\pi }\frac{(a^2-b^2)\cos t\sin t-iab }{a^2\sin^2 t + b^2\cos^2 t} dt \\
\end{align}
The real part of this integral is
$$ -\frac{ab}{2\pi }\int_0^{2\pi }\frac{dt}{a^2\sin^2 t + b^2\cos^2 t} $$
which gives your result (and the imaginary part is of course zero).
