For any $x \in \mathbf{R}$, the inequality
$$
\sin ^{2} x+m \sin x+\frac{m^{2}-3}{m} \leqslant 0
$$

always holds. Then the range of $m$ is $(\quad)$.
(A) $m \leqslant-\frac{3}{2}$
(B) $0<m \leqslant 1$
(C) $0<m \leqslant 3$
(D) $m \leqslant-\frac{3}{2}$ or $0<m \leqslant 3$
5. B.

Let $t=\sin x$, and denote $g(t)=t^{2}+m t+\frac{m^{2}-3}{m}$.
Then the given condition is transformed into, when $t \in[-1,1]$, $g(t) \leqslant 0$ always holds. This is equivalent to
$$
\left\{\begin{array}{l}
g(1)=1+m+\frac{m^{2}-3}{m}=\frac{2 m^{2}+m-3}{m} \leqslant 0, \\
g(-1)=1-m+\frac{m^{2}-3}{m}=\frac{m-3}{m} \leqslant 0 .
\end{array}\right.
$$

Solving this, we get $\left\{\begin{array}{l}m \leqslant-\frac{3}{2} \text { or } 0<m \leqslant 1, \\ 0<m \leqslant 3 .\end{array}\right.$
Therefore, $0<m \leqslant 1$.