\[ a x y(x)^2+b x+x y'(x)+2 y(x)=0 \] ✓ Mathematica : cpu = 0.118798 (sec), leaf count = 43
DSolve[b*x + 2*y[x] + a*x*y[x]^2 + x*Derivative[1][y][x] == 0,y[x],x]
\[\left \{\left \{y(x)\to -\frac {1}{a x}-\sqrt {\frac {b}{a}} \tan \left (a x \sqrt {\frac {b}{a}}-c_1\right )\right \}\right \}\] ✓ Maple : cpu = 0.066 (sec), leaf count = 63
dsolve(x*diff(y(x),x)+a*x*y(x)^2+2*y(x)+b*x = 0,y(x))
\[y \left (x \right ) = -\frac {-\frac {i \sqrt {a}\, \sqrt {b}\, x -1}{x}+\frac {{\mathrm e}^{-2 i \sqrt {a}\, \sqrt {b}\, x}}{c_{1}-\frac {i {\mathrm e}^{-2 i \sqrt {a}\, \sqrt {b}\, x}}{2 \sqrt {a}\, \sqrt {b}}}}{a}\]
Hand solution
\(xy^{\prime }+axy^{2}+2y+bx=0\)This is Riccati non-linear first order. Converting it to standard form\begin {align} y^{\prime } & =-b-\frac {2}{x}y-ay^{2}\tag {1}\\ & =f_{0}+f_{1}y+f_{2}y^{2}\nonumber \end {align}
Using transformation suggested by Kamke \(y=u\left ( x\right ) -\frac {1}{ax}\) then \(y^{\prime }=u^{\prime }+\frac {1}{ax^{2}}\). Equating this to RHS of (1) gives\begin {align*} u^{\prime }+\frac {1}{ax^{2}} & =-b-\frac {2}{x}\left ( u-\frac {1}{ax}\right ) -a\left ( u-\frac {1}{ax}\right ) ^{2}\\ & =-b-\frac {2}{x}u+\frac {2}{ax^{2}}-a\left ( u^{2}+\frac {1}{a^{2}x^{2}}-\frac {2u}{ax}\right ) \\ & =-b-\frac {2}{x}u+\frac {2}{ax^{2}}-au^{2}-\frac {1}{ax^{2}}+\frac {2u}{x} \end {align*}
Hence
\begin {align*} u^{\prime } & =-b-au^{2}\\ \frac {du}{dx} & =-b-au^{2} \end {align*}
This is separable
\[ \frac {du}{b+au^{2}}=-dx \]
Integrating
\begin {align*} \int \frac {du}{b+au^{2}} & =-x+C\\ \frac {1}{\sqrt {ba}}\arctan \left ( \frac {au}{\sqrt {ba}}\right ) & =-x+C\\ \arctan \left ( \frac {au}{\sqrt {ba}}\right ) & =-\sqrt {ba}x+C\\ u & =\frac {\sqrt {ba}}{a}\tan \left ( -\sqrt {ba}x+C\right ) \end {align*}
Hence
\begin {align*} y & =u-\frac {1}{ax}\\ & =\frac {\sqrt {ba}}{a}\tan \left ( -\sqrt {ba}x+C\right ) -\frac {1}{ax} \end {align*}
Verification
restart; ode:=x*diff(y(x),x)+a*x*y(x)^2+2*y(x)+b*x = 0; my_solution:=sqrt(b*a)/a*tan(-sqrt(b*a)*x+_C1)-1/(a*x); odetest(y(x)=my_solution,ode); 0