Author Topic: Problems on Windows with MSSQL  (Read 45 times)

Offline SMBiker

  • Jr. Member
  • **
  • Posts: 10
Problems on Windows with MSSQL
« on: May 26, 2020, 01:35:13 PM »
I am having issues running the newest release of Roundcube on my Windows server with MSSQL 2012 as a backend. It ran version 1.3.4 with no issues at all. It is running under PHP 7.2.24.

The problem is this: anytime Roundcube attempts to write something to the database, it reports an error back to the user. For instance, the first time a user logs into Roundcube, it reports that it can't create the user. Or, when you try to add a contact, it tells you that it failed. However...it doesn't fail, the SQL Insert actually succeeds - the row is inserted into the SQL database. What I suspect is that the rcube_db.affected_rows function is always reporting back zero, so that RoundCube thinks the insert failed, when it actually succeeded.

For instance, when a user tries to log in for the first time, Roundcube reports "Login failed" to the user, and the error log reports:

[May/25/2020 13:12:48 -0400]: <l61ucvcr> PHP Error: Failed to create new user in D:\inetpub\wwwroot\RoundCube\program\lib\Roundcube\rcube_user.php on line 703 (POST /?_task=login&_action=login)
[May/25/2020 13:12:48 -0400]: <l61ucvcr> PHP Error: Failed to create a user record. Maybe aborted by a plugin? in D:\inetpub\wwwroot\Roundcube\program\include\rcmail.php on line 652 (POST /?_task=login&_action=login)

Despite these reports, the user record did actually get created in the SQL table. So if they try to log in again using the exact same credentials, the login then succeeds.

This is a bone stock Roundcube install, fresh out of the box, no other plugins.

Doing a little bit of debugging, it appears to be that MSSQL does not return the inserted row as the resultset, at least by default. Looking at line 639 of /program/lib/Roundcube/rcube_user.php:

Code: [Select]
        if ($dbh->affected_rows($insert) && ($user_id = $dbh->insert_id('users'))) {
            // create rcube_user instance to make plugin hooks work
            $user_instance = new rcube_user($user_id, array(

My debugging shows that while the row is created successfully, $dbh->insert_id('users') contains nothing, and therefore Roundcube thinks the insert failed. It appears to be the case for EVERY insert function within Roundcube. I will admit that PHP is very far from my language of choice.

I suspect that nobody actually tested this version of Roundcube under MSSQL? I can't be the only one experiencing this.

Offline alec

  • Hero Member
  • *****
  • Posts: 1,187
Re: Problems on Windows with MSSQL
« Reply #1 on: May 26, 2020, 02:13:36 PM »
What driver are you using? Try using "sqlsrv:" prefix in db_dsn*.

Offline SMBiker

  • Jr. Member
  • **
  • Posts: 10
Re: Problems on Windows with MSSQL
« Reply #2 on: May 26, 2020, 03:31:43 PM »
What driver are you using? Try using "sqlsrv:" prefix in db_dsn*.

That is the prefix I'm using, so it's using the PDO sqlsrv driver.

My old mail server, running the same OS, SQL Server version and PHP version (but version 1.3.4) also used the exact same SQL driver with no problems.

Looking at the 1.3.4 code, it too pulls back the ID in the exact same way (the code is identical), so unless there's something different in underlying DB abstraction code, I'm not sure what might be different.