by Luis de Vasconcelos.
Turn on Debugging and you will get a bit of extra information with that "Error writing to database" message. That should help track down the problem.
Did you make any changes to your Moodle environment (web server, database, Moodle code, etc.) before you started getting this error?