Connecting moodle to a remote SQLServer database

Connecting moodle to a remote SQLServer database

by Mahomed Ouedraogo -
Number of replies: 3

Hello community!

I'm encountering a problem connecting my Moodle platform housed in a virtual machine to its database housed in SQLServer on the host machine. When I try to access my platform, I get this error:

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

This is my configuration:

-       Technical information Host machine

  • Operating system : Windows 10
  • Hypervisor : VMware.Workstation.15.5.1.15018445
  • DataBase : SQLServer Express 2017
  • Browser : chrome, firefox

-       Technical information virtual machine

  • Virtual machine: CentOS-8.1.1911-x86_64-dvd1
  • Server version: Apache/2.4.37
  • Version Moodle précise : 3.9
  • Version PHP 7.4

What I did:
In my Windows 10 physical machine, I installed a hypervisor and the SQLServer DBMS to house the data bade.
In my hypervisor, I created a virtual machine with CentOs 8 as operating system.
In the virtual machine, I installed :

  • the Microsoft Drivers for PHP for SQL Server
  • The apache server and PHP
  • Then I migrated my Moodle platform to the /var/www/html directory of Apache.

In the configuration file in my Moodle folder, I put the information as in the table below:

$CFG->dbtype    = 'sqlsrv';

 

$CFG->dblibrary = 'native';

 

$CFG->dbhost    = 'DESKTOP-OUUVQUE\MSSQLSERVER2017';

Address and instance of the database server

$CFG->dbname    = 'formation';

Name of the database created in SQLServer

$CFG->dbuser    = 'formation';

User associated with the training database

$CFG->dbpass    = '****************';

Database password

$CFG->prefix    = 'form_';

Table prefix

$CFG->dboptions = array (

  'dbpersist' => 0,

  'dbport' => '',

  'dbsocket' => '',

  'dbcollation' => 'utf8mb4_unicode_ci',

);

 

$CFG->wwwroot   = 'http://192.168.43.128/formation';

Access address to the platform on the virtual machine

$CFG->dataroot  = '/var/www/moodledata';

Moodle data directory address

$CFG->admin     = 'admin';

 

$CFG->directorypermissions = 0777;

 

require_once(__DIR__ . '/lib/setup.php');

 

Does anyone have any idea where the problem lies?

Thank you.

Average of ratings: -
In reply to Mahomed Ouedraogo

Re: Connecting moodle to a remote SQLServer database

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

Moodle (via the PHP sqlsrv extension) needs to be able to connect to SQL Server over the network. Can the CenOS VM resolve DESKTOP-OUUVQUE to an IP address and is it an IP address it can connect to the Windows 10 host on? I think you can specify an IP address in $CFG->dbhost e.g. '192.168.0.1\MSSQLSERVER2017'.

I don't think it's part of the problem but utf8mb4_unicode_ci is MySQL/MariaDB specific, see here for SQL Server settings including collation.

Average of ratings: Useful (1)
In reply to Leon Stringer

Re: Connecting moodle to a remote SQLServer database

by Mahomed Ouedraogo -
I applied the changes as you said:

  • CFG->dbhost = '192.168.1.113\MSSQLSERVER2017';
  • dbcollation' => 'Latin1_General_CS_AS'.
But unfortunately it's always the same mistake:

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
In reply to Mahomed Ouedraogo

Re: Connecting moodle to a remote SQLServer database

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

Have you configured SQL Server to allow TCP/IP connections? And is this listening on the 192.168.1.113 interface? This is configured in SQL Server Configuration Manager, e.g. (your settings may vary):

SQL Server Configuration Manager screenshot showing Network Configuration

You can also use Telnet on the VM to test the network connection (e.g. telnet 192.168.1.113 1433, you may need to install the Telnet client first: dnf install telnet). If you can't connect like this then Moodle won't be able to connect either.