I want to evaluate this integral:
$$\int{\frac{ax+b}{(x^2+2px+q)^n}}dx$$
The book only says to integrate by parts $\int{\dfrac{1}{(x^2+2px+q)^{n-1}}dx}$, for simplicity if $n = 2$ I get: $\int{\dfrac{1}{(x^2+2px+q)}dx}=\dfrac{x}{x^2+2px+q}+\int{\dfrac{2x^2+2px}{(x^2+2px+q)^2}}dx$.
Now I don't know what to do.
To answer your specific question, here is a trick that will work. Note that $$2x^2+2px=(2x^2+4px+2q)-2px-2q=(2x^2+4px +2q)-p(2x+2p)-2q+2p^2.$$ It follows that $$\int \frac{dx}{x^2+2px+q}=\frac{x}{x^2+2px+q} +2\int \frac{x^2+2px+q}{(x^2+2px+q)^2}\,dx -p\int \frac{2x+2p}{(x^2+2px+q)^2}\,dx+ (2p^2-2q)\int \frac{dx}{(x^2+2px+q)^2}.$$ On the right, the first integral is just the integral on the left. The second integral yields to the substitution $u=x^2+2px+q$. And the third integral is the one we wanted to evaluate. So we can express $\int \frac{dx}{(x^2+2px+q)^2}$ in terms of $\int \frac{dx}{x^2+px+q}$ except in the case $p^2=q$. But in that case $(x^2+2px+q=(x+p)^2$, and the integration is easy without going through the integration by parts.
It would have been easier to make the immediate substitution $x+p=y$, but I wanted to carry on from the point you had reached.
What follows is the beginning of much longer answer I had typed. The reduction formula got unpleasant to work with, so below is only the beginning of that answer.
We have $ax+b=\frac{a}{2}(2x+2p)+ b-ap$. So our integral is $$\frac{a}{2}\int \frac{2x+2p}{(x^2+2px+q)^n}\,dx+ (b-ap)\int \frac{dx}{(x^2+2px+q)^n}.\tag{$1$}$$ The first integral in $(1)$ is found by making the substitution $u=x^2+2px+q$. So we are integrating a power of $u$, easy.
The second integral in $(1)$ is not so easy! We use, repeatedly if necessary, a Reduction Formula (they are discussed in great detail in Wikipedia).
For any positive integer $n$, let $$I_n=\int \frac{dx}{(x^2+2x+q)^n}.$$ We show how to find a general expression for $I_n$ in terms of $I_{n-1}$. Thus if we start with for example $n=3$, we express $I_3$ in terms of $I_2$, then $I_2$ in terms of $I_1$.
Finally, $I_1$ breaks up into cases. Complete the square to get $x^2+2px+q=(x+p)^2+q-p^2$. If $q-p^2=0$, we had an easy integral to begin with, and the Reduction Formula was a waste of time. If $q-p^2\gt 0$, a substitution brings us to $\int \frac{1}{u^2+1}$. If $q-p^2\lt 0$, use partial fractions.
Now we begin the reduction. As in what you did, we use integration by parts. It is easier for me to go backwards. So we calculate $I_{n-1}$ using integration by parts. Let $n\ge 2$. We have $$I_{n-1}=\int \frac{dx}{(x^2+2px+q)^{n-1}}.$$ Let $u=\frac{1}{(x^2+2px+q)^{n-1}}$ and let $dv=dx$. Then $du=-\frac{(n-1)(2x+2p)}{(x^2+2px+q)^n}$ and we can take $v=x$. So $$I_{n-1}= \frac{x}{(x^2+2px+q)^{n-1}}+(n-1)\int \frac{2x^2+2px}{(x^2+2px+q)^{n}}\,dx.$$ To finish, use the same trick as the one at the beginning of the post. However, you will find the calculation far more pleasant with the preliminary change of variable $y=x+p$.