The equilibrium state reached upon dissolving a weak electrolyte in water is described by a special kind of equilibrium constant, ksp, which is a function of the standard free energy change of reactants and products. The enthalpy change (heat flow), an important component of free energy change, very nearly equals the change in internal energy because system volume is very nearly constant (no pressure-volume work is involved). Furthermore, this internal energy change primarily depends on the change in the electrostatic potential energy at the molecular level between the system as solute and solvent as compared to final solution. Hess's Law gives us permission to conceptualize the internal energy change as the act of pulling solute and solvent particles apart, an internal energy increase, and letting them fall together into solution, a decrease in internal energy (this is not the true path, of course, but the overall internal energy change would be the same, having the same initial and final state).
In addition to the heat flow (internal energy change, electrostatic potential energy), that plays a roll in determining the difference between the undissolved and dissolved state is the difference in entropy. Despite the entropy of mixture, which might make you think that dissolving an electrolyte in water increases the entropy of the system, the solution process involving an electrolyte in water actually causes the entropy to decrease, because the water molecules become more ordered as they are constrained in the orderly geometry of hydration spheres. This occurs despite the entropy of mixture, which would dominate in the solution of an organic solute in an organic solvent, where there is very little constraint to molecular orientation. With a typical nonpolar solute in nonpolar solvent, the entropy definitely increases in the system over the course of the solution process, but when ions are dissolved in water, the system increases in its order.
Let us finish this discussion with the question. Why do salts dissolve at all? Almost all solution processes are endothermic (solubility increases with temperature, Le Chatelier's Principle). Furthermore, the solution of an electrolyte in an aqueous solution represents more order. Why then, when you place the salt in water, does it spontaneously dissolve, even if only sparingly? The answer is that our question is off base. When you have a salt ready to dissolve in pure water, you are not looking at a system with equal amounts of Reagents A and Products B. The answer is that your initial state is not the Standard State (quantifying the Standard State is a complicated problem for a nonhomogeneous process like this, i.e. having both solids and liquids). In the initial state of the solution process, you are starting with only Reagents A. Of course the direction the reaction takes toward equilibrium is toward the products, in other words, dissolving, even though a Standard State comparison of the solution process has positive free energy. The greater this positive free energy change, though, the less soluble the salt will be.
I don't do this too often, but this is a repeat of an early discussion in Chemimical Thermodynamics. Comprehension here corresponds to superior understanding of a crucial set of concepts.