Answer
$y=x\sin x-kx\cos x+k'x\sin x$
Work Step by Step
Given $x^2y''+2xy'+(x^2+2)y=0$
We first compute the appropriate derivatives:
$y'=x\sin x(u'+u)\\
y''=x\sin x(u''+u'+u)$
Substitute:
$x^2[x\sin x(u''+u'+u)]+2x\sin x(u'+u)+(x^2+2)x\sin x=0$
which simplifies to
$x^3u''\sin x+2^3\cos xu'=0$
or equivalently,
$w'x+w=0$
where $w=u'$
Separating the variables yields
$-2\cot x=\frac{w}{w'}$
By integrating, we obtain
$\ln w=-2\ln (\sin x) +C\\
wx=k$
Therefore,
$u'=\frac{k}{\sin^2x}$
Integration by parts gives
$u=-k\cot x +k'$
The general solution is
$y=x\sin x-kx\cos x+k'x\sin x$