Trying to connect using FreeTDS driver

Re: Trying to connect using FreeTDS driver

by Albert Ramsbottom -
Number of replies: 11

I may have installed the wrong version of the TDS driver

I have now downloaded the 5.4nts version and I am now getting the following error, which is very odd


Config table does not contain version, can not continue, sorry.

More information about this error

It is usually not possible to recover from errors triggered during installation, you may need to create a new database or use a different database prefix if you want to retry the installation.


Any ideas, nothing elese on the screen

In reply to Albert Ramsbottom

Re: Trying to connect using FreeTDS driver

by Luis de Vasconcelos -

It seems that Moodle didn't install correctly. Is it a new Moodle installation? If so, drop and re-create the database. Empty out the Moodledata folder and then start the Moodle installation again. It's the safest option, rather than trying to fix a half-broken installation.

In reply to Luis de Vasconcelos

Re: Trying to connect using FreeTDS driver

by Albert Ramsbottom -

Hi

Moodle installed correctly and has been running for 4 months and works perfectly smile


It is only when I switch the PHP.ini to use the TDS driver that this happens. When I switch back its fine


Cheers

In reply to Albert Ramsbottom

Re: Trying to connect using FreeTDS driver

by Albert Ramsbottom -

Log files:

sqlsrv_connect: message = [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections.

I am using the same DB connection string from my config.php in the FreetDS.conf

I have tested with and without $CFG->dblibrary = 'native'; in config

Here is my full config for FreeTDS driver

$CFG->dbtype    = 'mssql';
$CFG->dblibrary = 'native';
$CFG->dbhost    = 'myserver.local';
$CFG->dbname    = 'mydbname';
$CFG->dbuser    = 'mydbuser';
$CFG->dbpass    = 'mydbpassword';
$CFG->prefix    = 'mdl_';
$CFG->dboptions = array (
  'dbpersist' => 0,
  'dbsocket' => 0,
);

Here is my FreeTDS.conf which is stored in the root of the C:/ drive and also in the root of my PHP Dir

[global]
     host = myserver.locall
     port = 1433
     client charset = UTF-8
     tds version = 9.0
     text size = 20971520


I am using TDS 0.9 so I assume the TDS version would 9.0 as the Moodle docs suggest TDS version 8.0 when using version 0.8

Thanks

In reply to Albert Ramsbottom

Re: Trying to connect using FreeTDS driver

by Albert Ramsbottom -

OK so mysql extension was enabled which was messing it up

But now everything loads and seems fine until I go to resore and course made from an installation using the sqlsrvr drivers and now it complains that


mssqlnative extension not installed


But if I back up a course and restore from within the same install everything works fine


Am I right in assuming that one cannot swap to the freeTDS driver, but only undertake a new install?


Cheers


In reply to Albert Ramsbottom

Re: Trying to connect using FreeTDS driver

by Albert Ramsbottom -

OK I still have a an issue but I have got it working

Here are the installation instructions

Installation instructions

1.       Copy php_dblib to C:\php-5.4.29-VC9\ext (make sure this is the right PHP directory

2.      Add the following extensions in the php.ini:

extension=php_dblib.dll

comment the following extensions:

;extension=php_sqlsrv_54_nts.dll

;extension=php_mysql.dll

[PHP_MYSQLI]

;extension=php_mysqli.dll

 

3.       Change the moodle.config, making sure you change the SQL to suit your installation

$CFG->dbtype    = 'mssql';

//$CFG->dblibrary = 'native';

$CFG->dbhost    = 'yourdbserver';

$CFG->dbname    = 'youdbname';

$CFG->dbuser    = 'yourdbuser';

$CFG->dbpass    = 'youdbpassword';

$CFG->prefix    = 'mdl_';

$CFG->dboptions = array (

  'dbpersist' => 0,

  'dbsocket' => 0,

);

 

4.      Add the freetds.conf to C:/ root, making sure you change the sql server to suit your installation

[global]

     host = sameasmoodleconfigl

     port = 1433

     client charset = UTF-8

     tds version = 8.0

     text size = 20971520

 

5.       Change the sql driver to MSSQL in Moodle; Site administration > Plugins > Enrolments >External Database > Database Driver

6.    Restart IIS



In reply to Albert Ramsbottom

Re: Trying to connect using FreeTDS driver

by Albert Ramsbottom -

I still have one issue, if I run the security report it appears to be still trying to use the MSSQL native driver and I am not sure why

Debug info:
SELECT COUNT(DISTINCT u.id) FROM (SELECT rcx.*
FROM mdl_role_capabilities rcx
JOIN mdl_capabilities cap ON (cap.name = rcx.capability AND ((cap.riskbitmask) & (4)) <> 0)
WHERE rcx.permission = ?) rc,
mdl_context c,
mdl_context sc,
mdl_role_assignments ra,
mdl_user u
WHERE c.id = rc.contextid
AND (sc.path = c.path OR sc.path LIKE CAST(c.path AS NVARCHAR(255)) + CAST('/%' AS NVARCHAR(255)) OR c.path LIKE CAST(sc.path AS NVARCHAR(255)) + CAST('/%' AS NVARCHAR(255)) )
AND u.id = ra.userid AND u.deleted = 0
AND ra.contextid = sc.id AND ra.roleid = rc.roleid
[array (
0 => 1,
)]
Error code: dmlreadexception
Stack trace:
  • line 443 of \lib\dml\moodle_database.php: dml_read_exception thrown
  • line 242 of \lib\dml\mssql_native_moodle_database.php: call to moodle_database->query_end()
  • line 724 of \lib\dml\mssql_native_moodle_database.php: call to mssql_native_moodle_database->query_end()
  • line 758 of \lib\dml\mssql_native_moodle_database.php: call to mssql_native_moodle_database->get_recordset_sql()
  • line 1476 of \lib\dml\moodle_database.php: call to mssql_native_moodle_database->get_records_sql()
  • line 1549 of \lib\dml\moodle_database.php: call to moodle_database->get_record_sql()
  • line 1759 of \lib\dml\moodle_database.php: call to moodle_database->get_field_sql()
  • line 476 of \report\security\locallib.php: call to moodle_database->count_records_sql()
  • line 112 of \report\security\index.php: call to report_security_check_riskxss()

In reply to Albert Ramsbottom

Re: Trying to connect using FreeTDS driver

by Luis de Vasconcelos -

What happens when you use:

tds version = 7.3

instead of 9.0?

http://www.freetds.org/userguide/choosingtdsprotocol.htm says: "... when Microsoft started releasing official specs of the protocol, it became obvious that the TDS versions that FreeTDS had labeled 8.0 and 9.0 were actually versions 7.1 and 7.2 respectively. For compatibility reasons version 8.0 is still handled by FreeTDS but you should avoid using it as it could be removed in a future version of FreeTDS or it could clash with a future SQL server version."

You could also try 7.4, but in http://lists.ibiblio.org/pipermail/freetds/2015q2/029439.html Frediano (who is one of the FreeTDS developers) says:  "7.3 is fine. master support 7.4 but there are no improvements (support some session recovery which are not implemented anyway)".

In that message he explicitly states that "sql 2012 and sql 2014 use same protocol (7.4)".

So, as I understand that, you should use "tds version = 7.3" when connecting to any version of MS SQL Server from 2008 and up.

In reply to Luis de Vasconcelos

Re: Trying to connect using FreeTDS driver

by Albert Ramsbottom -

If I change the freetds.conf to anything other than

tds version = 8.0

it fails with a weird error and mostly empty screen

I am actually using version 0.91.102 NTS version as I am using PHP.5.4


Great info


In reply to Albert Ramsbottom

Re: Trying to connect using FreeTDS driver

by Luis de Vasconcelos -

What's that "weird error"?

Does PHPInfo() contain a "MSSQL" section when you use "tds version = 7.3"?

In reply to Albert Ramsbottom

Re: Trying to connect using FreeTDS driver

by Luis de Vasconcelos -

Also, have you set the TDSVER environment variable? If so, what version does it reflect?

http://www.freetds.org/userguide/envvar.htm


In reply to Luis de Vasconcelos

Re: Trying to connect using FreeTDS driver

by Albert Ramsbottom -

Thanks for your help on this

The weird error is set out above, its a weird upgrade error

However when it works, everything works except for the security overview, the rest of the sites works great

I didn't set the environmental variable because I just left the freetds.conf in the C:/

So now everything appears to be good, apart from oddly the security overview report which to be honest is not that important.  I am thinking it might be a bug insofar as a bug that presents itself when one changes a current installation from the standard PHP "sqlsvr" driver to the freeTDS one


Albert