On the other hand, the "...!!! Error writing to database !!!" error message usually means a LDAP settings configuration error. But you'll need to enable debugging in Moodle in order to get the actual database error message. That message will help diagnose the configuration problem.
In addition to that, specifying your Moodle version would certainly help