Let $A$ be a closed densely-defined symmetric linear operator on a Hilbert space $H$ that is not selfadjoint. Let $B=A$. Then $(Ax,y)=(x,By)$ for all $x,y\in\mathcal{D}(A)=\mathcal{D}(B)$ because $A$ is symmetric. However, $A^{\star} \ne B$ because $A^*\ne A$, as $A$ is not selfadjoint.
Example: Let $H=L^2[0,1]$. Let $A=\frac{1}{i}\frac{d}{dx}$ on the domain consisting of $f \in L^2[0,1]$ that is equal a.e. to an absolutely continuous function $f_a$ on $[0,1]$ for which $f_a'\in L^2$, and such that $f_a(0)=f_a(1)=0$. Let $B=A$. Then $A$ is closed and densely-defined, with
$$
(Af,g)-(f,Bg) = \frac{1}{i}\int_{0}^{1}f'\overline{g}+f\overline{g}'dt=0,\;\;\; f,g\in\mathcal{D}(A)=\mathcal{D}(B).
$$
However, $B \ne A^*$ because the constant function $1$ is in the domain of $A^*$ but not in the domain of $B$, as seen from
\begin{align}
(Af,1) & = \frac{1}{i}\int_{0}^{1}f'dt = \frac{1}{i}[f_a(1)-f_a(0)]=0\\
& \implies (Af,1)=(f,0),\;\; f\in\mathcal{D}(A) \\
& \implies 1\in\mathcal{D}(A^*) \mbox{ and } A^*1 = 0.
\end{align}