Based on your question I'm assuming that you have shell access to the WeBWorK server, but not to the database server.
WeBWorK doesn't have a perpetual connection to the database. Each time it needs to query the database it opens a connection, and then closes it when the query completes.
There are a couple of options for accomplishing what you ask. One is to modify the WeBWorK code so that when a database connection fails it sends an email notification. Another choice would be to write a script on your WeBWorK server that periodically tries to connect to the database, and if the connection fails it sends an email.
The former would not trigger an email until something in WeBWorK tried to connect to the database. The latter would run as often as you ask. Depending on how often you chose to have it run, it could cause extra strain on your servers.
Of courses there are also more robust solutions involving installing monitoring software, but you would have to investigate these.