"PS: It is an electrical switch 4wd with the switch on the dash."
Yep, but that switch just initiates the process.
The powertrain 'puter then looks at lots of stuff, likely front and rear wheel speed, front and rear driveshaft speed, vehicle speed, temperature, engine load, what the ABS or traction control system is doing, etc., etc., etc., before deciding if the shift into 4X4 you asked for is actually going to happen.
Unless you see something obvious wrong (like you wondered, ground wire disconnected), you are gonna need a scan tool to see what is irritating the 'puter into turning the MIL lite on and refusing to complete the shift.
MIGHT not hurt to drive it, but I would check for the loose wire, then scan it if necessary and fix it BEFORE putting miles on it.
LOTS of $$$$$ possibly involved if the choice to drive it is not a good one!