I stated several times that I put this proc definition in a "blah-procs" file in a tcl folder. In other words, I put it in a file that is supposed to "auto-run" when the system starts.
Which is not a way to "dynamically define this proc".
At any rate, everything is working fine now. The problem (as someone pointed out) was accessing a system proc when there wasn't a connection.