Error: Database Connection Failed

Error: Database Connection Failed

by Fran Johnson -
Number of replies: 4

Hello,

Basic details: Moodle version: 3.3.5, PHP: 7.1.22, servers Windows 2016 database and web.

Description: I'm struggling to clone/migrate a moodle site to a newer host web and database server. I've done this with other moodle sites so I have settings to reference and have gone over those many times. Have read all I can find online and in the forum about this issue, combed through the config.php settings, tested database and dbuser accounts, tested PHP and reset PHP folders, and looked at PHP logs. Database server looks healthy - plenty of room on all drives. Ran maintenance plan on database to rebuild indexes and clean data, which passed. Am at a bit of a loss. Am thinking it could be a random setting on this new web server because the database server is housing other databases that are not having any issues.

Full error message: Error: Database connection failed - It is possible that the database is overloaded or otherwise not running properly. The site administrator should also check that the database details have been correctly specified in config.php. 

Any suggestions would be very welcome! 

Thank you!!database connection failed

Average of ratings: -
In reply to Fran Johnson

Re: Error: Database Connection Failed

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
I am not the best at these kinds of problems, especially with Windows servers, but I will provide some ideas.

1) On your new server, have you ever been able to install a brand new Moodle successfully? In other words, can your new server run Moodle?
2) You say "migrate." Are you trying to use the exact same version of Moodle, meaning 3.3.5, on both servers? If so, you might try installing a brand new 3.3.5 on this new server to see if it can run.
In reply to Fran Johnson

Re: Error: Database Connection Failed

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

"It is possible that the database is overloaded or otherwise not running properly" - ignore this, fundamentally this error means Moodle's connection attempt to the database has failed which is typically caused by one of:

  1. The PHP extension for the database driver is missing, either php-mysqli (for MySQL and MariaDB), php-pgsql (for PostgreSQL) or php-sqlsrv (for SQL Server).
  2. The connection details are wrong in config.php, check $CFG->dbtype, $CFG->dbhost, $CFG->dbname, $CFG->dbuser, $CFG->dbpass and $CFG->dboptions. (It sounds like you've done this).
  3. The database service isn't running. (It sounds like you've checked this).
  4. The network connection to the database couldn't be established, e.g. if blocked by a firewall. This is unlikely to be an issue if the database is on the same server as the web server.

Can you tell us the database type (MySQL, MariaDB, PostgreSQL or SQL Server) and version?

@error_reporting(E_ALL | E_STRICT);
@ini_set('display_errors', '1');
$CFG->debug = (E_ALL | E_STRICT);
$CFG->debugdisplay = 1;
These must appear before the line require_once(__DIR__ . '/lib/setup.php');. Hopefully this will show more details with the error.
In reply to Leon Stringer

Re: Error: Database Connection Failed

by Fran Johnson -
Hi Leon,
1) this is a sql server. The main drivers I believe it's using are: extension=php_sqlsrv_71_nts, set in the php.ini. I've tried swapping out these folders with PHP and PHP 7.1 folders from working servers, and also pointing to the drivers in PHP vs PHP_7.1 ext folders - so far, no luck. I don't see anything in the PHP logs that would indicate a problem but I'm not sure how helpful they really are in this type of situation.
2) yeah, I'm pretty sure it's not the config file - I'll feel REAL dump if it is, but I've looked at those settings and copied over settings from working site, just adjusting the necessary lines, several times
3) database seems to be in good shape
4) it's funny you mentioned this - I just reached out to out network folks to check on this very thing - fingers crossed this is it!

Database type is SQL Server, Standard Edition 2016

I have tried debugging - no luck. Although I never realized the require_once line had to be under the debug info. I moved it to the correct place - still no luck but good to know
In reply to Fran Johnson

Re: Error: Database Connection Failed

by Fran Johnson -
I found the problem - the web server was missing it's SQL ODBC drivers - ugh!! Should have checked that days ago. Oh well, live and learn. Leon and Rick, thank you for the troubleshooting help!