W.l.o.g. we can assume that $a>0$ (because, otherwise one can replace $a$ with its absolute value)
Setting
$$
x=a\tan(u),
$$
we have
$$
dx=a\sec^2(u)du,
$$
so we get
\begin{eqnarray}
\int\sqrt{x^2+a^2}dx
&=&\int a\sec^2(u)\sqrt{a^2\tan^2(u)+a^2}du\\
&=&\int a\sec^2(u)\sqrt{a^2(1+\tan^2(u))}du\\
&=&\int a\sec^2(u)\sqrt{a^2\sec^2(u)}du\\
&=& a^2\int \sec^3(u)du
\end{eqnarray}
Using integration by parts, we have
\begin{eqnarray}
\int \sec^3(u)du
&=&\int \sec(u)[\tan(u)]’du\\
&=& \sec(u)\tan(u)-\int \tan(u)]\sec(u)]’du\\
&=&\sec(u)\tan(u)-\int\tan(u)\sec(u)\tan(u)du\\
&=&\sec(u)\tan(u)-\int\sec(u)\tan^2(u)du\\
&=&\sec(u)\tan(u)-\int\sec(u)[\sec^2(u)-1]du\\
&=&\sec(u)\tan(u)+\int\sec(u)du-\int\sec^3(u)du\\
&=&\sec(u)\tan(u)+\ln|\sec(u)+\tan(u)|+2B-\int\sec^3(u)du
\end{eqnarray}
where $B$ is an arbitrary constant. Therefore
$$
\int\sec^3(u)du=\frac12\sec(u)\tan(u)+\frac12\ln|\sec(u)+\tan(u)|+B.
$$
Since
$$
\tan(u)=\frac{x}{a},
$$
we have
$$
\sec(u)=\frac1a\sqrt{x^2+a^2}.
$$
Hence
$$
\int\sqrt{x^2+a^2}dx=\frac12x\sqrt{x^2+a^2}+\frac12a^2\ln|x+\sqrt{x^2+a^2}|+C
$$
where
$$
C=B-\frac12a^2\ln(a).
$$