Applying Gauss' Divergence Theorem to given integral We are given the following two integrals:
$$\iint\limits_S D_n f\:dS $$ and
$$\iiint\limits_B \nabla \cdot (\nabla f) \: dV$$
where $S$ is the portion of the sphere $x^2+y^2+z^2=a^2$ in the first octant, $n$ is the unit normal vector to $S$ at $(x,y,z)$ and $f(x,y,z) = ln(x^2+y^2+z^2)$
For the first integral, we have:
$D_n f = \nabla f \cdot n$ and $n = \frac{1}{a}<x,y,z>$
Since $\nabla f = \: <\frac{2x}{x^2+y^2+z^2}, \frac{2y}{x^2+y^2+z^2}, \frac{2z}{x^2+y^2+z^2}>$, this gives $D_n f = \nabla f \cdot n = \frac{2}{a}$.
So the integral becomes
$$\iint\limits_S D_nf \: dS = \iint\limits_S \frac{2}{a} \: dS = \frac{2}{a} \iint\limits_S dS = \frac{2}{a} \cdot A(S) = \frac{2}{a} \cdot 4\pi a^2 \cdot \frac{1}{8} = \pi a$$ ($\frac{1}{8}$ since the sphere is in the first octant)
For the second integral, we have
$\nabla \cdot (\nabla f) = \frac{2}{a^2}$ (since $x^2 + y^2 + z^2 = a^2$).
So the integral becomes
$$\iiint\limits_B \nabla \cdot (\nabla f) \: dV = \frac{2}{a^2} \iiint\limits_B dV = \frac{2}{a^2} \cdot V(B) = \frac{2}{a^2} \cdot \frac{4}{3} \pi a^3 \cdot \frac{1}{8} = \frac{1}{3} \pi a$$
However, according to Gauss' Divergence theorem, these two integrals should be equal to each other right? Since we have
$$\iiint\limits_B \nabla \cdot (\nabla f) \: dV = \iint\limits_S \nabla f \cdot dS = \iint\limits_S \nabla f \cdot n \: dS = \iint\limits_S D_n f \: dS$$
So how is it possible that I get two different answers, even though the Divergence theorem shows that the two integrals should be the same?

To apply divergence theorem, you must have a closed surface. So we close the surface by placing $3$ quarter disks in plane $x = 0, y = 0, z = 0$.
Please note that when you are doing volume integral, you cannot equate $\nabla \cdot (\nabla f) = \displaystyle \frac{2}{x^2+y^2+z^2} = \frac{2}{a^2}$. It should rather be,
$\nabla \cdot (\nabla f) = \displaystyle \frac{2}{x^2+y^2+z^2} = \frac{2}{\rho^2}$
So the integral becomes,
$\displaystyle \int_0^{\pi/2} \int_0^{\pi/2} \int_0^a \frac{2}{\rho^2} \ \cdot\rho^2 \cdot \sin \phi \ d\rho \ d\phi \ d\theta = \pi a$.
Now to find flux through $S$, we must subtract flux through planar surfaces $x = 0, y = 0, z = 0$ but in this case, they are simply zero.
