After upgrading a site to 2.x, an admin or teacher may receive an error, "Error writing to database," when attempting to reset a course. course/reset_form.php grabs a list of all modules from mdl_modules and then loops over them to count instances of each in the course. When a table with the module name doesn't exist or the table doesn't contain the expected 'course' field, an exception is thrown and the user receives an error. Expected behavior is to not receive an error and be able to reset the course.
We tracked this down to the site having been upgraded from 1.9 to 2.0 and still having records in mdl_modules for modules that existed in 1.9 but haven't been updated for 2.0. To prevent the error and allow the user to reset the course, the simplest fix seems to be to wrap if (!$DB->count_records()) with a try/catch to catch the exception and continue to the next module. A patch is attached for that.