Answer
$$ y=1+ (x^2+1)^{-3/2}$$
Work Step by Step
Given $$\left(x^{2}+1\right) \frac{d y}{d x}+3 x(y-1)=0, \quad y(0)=2$$
Rewriting the equation as
$$ \frac{d y}{d x}+\frac{3x}{x^2+1} y =\frac{3x}{x^2+1} $$
Since the equation is linear and $p(x)= \frac{3x}{x^2+1} $ and $q(x)=\frac{3x}{x^2+1}$, then
\begin{align*}
\mu &=e^{\int p(x)}dx\\
&= e^{\int \frac{3x}{x^2+1} dx}\\
&=e^{\frac{3}{2}\ln (x^2+1)}\\
&=(x^2+1)^{3/2}
\end{align*}
Hence the general solution given by
\begin{align*}
\mu(x)y&=\int \mu(x)q(x)dx\\
(x^2+1)^{3/2} y&= \int(x^2+1)^{3/2} \frac{3x}{x^2+1} dx\ \ \\
&=\int3x\sqrt{x^2+1}dx\\
&=(x^2+1)^{3/2} +C
\end{align*}
Then
$$ y=1+C(x^2+1)^{-3/2}$$
Since $y(\pi )=0 $, then $C= 1$, hence
$$ y=1+ (x^2+1)^{-3/2}$$