you can't separate this so we will use an Integrating Factor
#dy/dx=(xy+2)/(x+1)#
#dy/dx - (x)/(x+1) y =(2)/(x+1)#
the integrating factor I(x) is
#I(x) = exp( int dx qquad - (x)/(x+1) )#
# = exp( - int dx qquad (x+ 1 - 1)/(x+1) )#
# = exp( - int dx qquad 1 - 1/(x+1) )#
# = exp( - (x - ln (x+1) ) )#
# = exp( ln (x+1) - x )#
# = e^( ln (x+1)) e^(- x) = (x+1) e^(- x) #
so multiplying both sides by #I(x)#
#(x+1) e^(- x)* dy/dx - (x+1) e^(- x)* (x)/(x+1) y =(2)/(x+1) * (x+1) e^(- x)#
#implies color{red}{(x+1) e^(- x)}* color{blue}{dy/dx} - color{red}{ x e^(- x)} color{blue}{ y} =2e^(- x)#
#implies ((x+1) e^(- x) y)^prime =2e^(- x)#
So
#(x+1) e^(- x) y = 2 int dx qquad e^(- x)#
#(x+1) e^(- x) y = -2 e^(- x) + C#
# y = (-2 + C e^(x))/(x+1)#