Error connecting to database - possible solution

Error connecting to database - possible solution

by Hal MacLean -
Number of replies: 4

I have just installed and been running Moodle 2.3.1+ (Build: 20120726), and trying to update some of the content in courses, specifically Scorm objects and Quiz objects. Uploading them and adding them to start with is fine, but any changes after the first save resulted in a less than helpful, pale yellow box on the screen saying 'Database Connection Failed'.

Doing some research into this turned up next to nothing - is your MySQL DB overloaded... are there write errors on your server. No, all that is fine... 

Turn on debugging (Site Administration/development/debugging) and make sure you show the developer level debug. Get this written to a server log if you can, but if not, check the first box under the drop down at the top of that settings page and have the error written to the page instead of to a log file (this *will* stop other things from working, be prepared!)

I then tried the Quiz update process again, and this time, I got the following on screen:

"Debug info: Column 'completionexpected' cannot be null

UPDATE mdl_course_modules SET course = ?,module = ?,instance = ?,section = ?,idnumber = ?,added = ?,score = ?,indent = ?,visible = ?,visibleold = ?,groupmode = ?,groupingid = ?,groupmembersonly = ?,completion = ?,completiongradeitemnumber = ?,completionview = ?,completionexpected = ?,availablefrom = ?,availableuntil = ?,showavailability = ?,showdescription = ? WHERE id=?"

plus the usual array information to fill in all those questionmarks.

The interesting bit is right at the start - completionexpected cannot be NULL... this means a table in the database has a row that must have data written to it. In my case, it turned out to be the mdl_course_modules table (as you can see fromt the start of the SQL query), and the row 'completionexpected' was set to prevent 'null' returns written to it.

Using a MySQL client, I logged in to the database, found the table and displayed the structure. Sure enough, the row was not allowing 'Null', so ticked the checkbox allow it and tried the Quiz update again. This time, it worked - as did the Scorm update.

My guess is either I've completely destroyed the logic behind the update process by doing this, or in this version of Moodle, that particular row in that specific table needs to be set to allow NULL to start with!

Oh - if you turn on the debugging and cannot get back to the page display in your browser because of the other information now on the page, go back into the database, look for the table called 'mdl_config' and look for the rows called debugdisplay and debugpageinfo and set them to '0'... then reload your browser display and it should all re-appear. You can then go back in to site admin/developer/debugging and turn off the developer information.

Hope this helps someone! Alternatively, if I've done something completely wrong, I hope someone lets me know!

 

Average of ratings: -
In reply to Hal MacLean

Re: Error connecting to database - possible solution

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

This shouldn't happen in the first place. Was this an upgrade or a clean install?

In reply to Howard Miller

Re: Error connecting to database - possible solution

by Hal MacLean -

Hi Howard - it was a clean install.

It might be there is something else at play here - we have a number of scripts working to prevent us needing to change the core code for moodle as we create bespoke functionality in some of the plugins. I currently have a developer looking at whether one of our scripts is giving the error... we suspect we might be causing it when comparing values for that field... in which case the db setting should be left as preventing null.

I'll have more info later today, I hope!

In reply to Hal MacLean

Re: Error connecting to database - possible solution

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

When you are using an older version, like 2.3.1, and you hit a bug, it is a good idea to upgrade to the latest version, which is now 2.3.6.

In reply to Tim Hunt

Re: Error connecting to database - possible solution

by Hal MacLean -

Thanks Tim - I agree.

We adjusted a script we are using which was causing a conflict with the default Moodle setting. Needless to say, changing the moodle DB was a workaround, but altering the script to remove the conflict was what we needed to do long-term!

In summary - I don't advise changing the db settings... smile