LDAP Sync Collation

LDAP Sync Collation

by Ryan Hanisco -
Number of replies: 1

Hi Everyone,

We are running Moodle 2.7 and installed on a Windows server and SQL 2008 R2.  Everything seems to work well....  but.

We did the installation according to the instructions setting the collation to: Latin1_General_CS_AS  as the instructions specify - I have verified this at the table and column level.  When we try to do a sync with AD, we get the error below which seems to indicate that it is expecting  SQL_Latin1_General_CP1_CI_AS rather  that the one in the instructions.

-- Has anyone worked through this issue? I am finding similar requests on the forum with no resolution.

-- If I just switch the collation to the one that LDAP seems to need, will there be other impacts to moodle?

C:\inetpub\wwwroot\Moodle\auth\ldap\cli>sync_users.php

Connecting to LDAP server...

Creating temporary table tmp_extuser

................................................................................

................................................................................

................................................................................

................................................................................

................................................................................

................................................................................

........................................................Got 536 records from LDAP

!!! Error reading from database !!!

!!! SQLState: 42000<br />

Error Code: 468<br />

Message: [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot resolve th

e collation conflict between "Latin1_General_CS_AS" and "SQL_Latin1_General_CP1_

CI_AS" in the equal to operation.<br />

SELECT e.id, e.username

                  FROM #mdl_tmp_extuser e

                  LEFT JOIN mdl_user u ON (e.username = u.username AND e.mnethos

tid = u.mnethostid)

                 WHERE u.id IS NULL

[array (

)]

Error code: dmlreadexception !!

!! Stack trace: * line 443 of \lib\dml\moodle_database.php: dml_read_exception thrown

* line 250 of \lib\dml\sqlsrv_native_moodle_database.php: call to moodle_database-&gt;query_end()

* line 357 of \lib\dml\sqlsrv_native_moodle_database.php: call to sqlsrv_native_moodle_database-&gt;query_end()

* line 792 of \lib\dml\sqlsrv_native_moodle_database.php: call to sqlsrv_native_moodle_database-&gt;do_query()

* line 840 of \lib\dml\sqlsrv_native_moodle_database.php: call to sqlsrv_native_moodle_database-&gt;get_recordset_sql()

* line 919 of \auth\ldap\auth.php: call to sqlsrv_native_moodle_database-&gt;get_records_sql()

* line 63 of \auth\ldap\cli\sync_users.php: call to auth_plugin_ldap-&gt;sync_users()


Average of ratings: -
In reply to Ryan Hanisco

Re: LDAP Sync Collation

by Ryan Hanisco -

Hey Folks,

I think I have an idea of what's going on here.  If I am right, I am surprised to see that this isn't an issue for more people. 

The instructions tell us that we have to set the collation of the Moodle database.  This is great, but the issue comes with the use of temp tables.  In MS-SQL, these are created in the TempDB which are created every time the database is restarted, inheriting their collation from the MasterDB.  This means that in any case where the default collation is different from the database collation we would see this conflict when using temp tables. 

With that, I am surprised that this isn't a common issue and can only think that either people are using single database instances for moodle or that creating temp tables isn't done often and only really comes out in the LDAP sync (since that is the only place I see people mention this in the forum.)

This means the solutions would be:

  • Create a separate SQL instance for Moodle
  • Rewrite the query with the 'collate database_default' in the code creating the temp table, though I don't know what this would do for users of other databases.
  • Change the collation of the database to match the default and hope nothing breaks

References:

http://msdn.microsoft.com/en-us/library/ms184391.aspx
http://www.sqlnotes.info/2012/05/07/collation-of-temp-tables/