Made register() disconnect from DB if something fails

If register() fails to write to the DB, it will now disconnect rather than
leaving a dangling connection.

Signed-off-by: Sebastian Lenartowicz <slenarto@uoguelph.ca>