phpsql-serverlinuxzend-framework2pdo-odbc

Connection busy to MS SQL Server on Linux using Zend Framework 2 and ODBC Driver


I needed to migrate a Windows server setup to a Linux (Red Hat 7.2) server. Previously we used the pdo_sqlsrv driver on the Windows machine. On the Linux we've installed the pdo_odbc driver. But since Zend Framework 2 doesn't support this out of the box, I figured out a db configuration myself using the ZF2 API docs which works now. This is the configuration:

'db' => array(
    'driver' => 'pdo',
    'username' => 'ourDbUsername',
    'password' => 'ourDbPassword',
    'dsn' => 'odbc:DRIVER={SQL Server Native Client 11.0};UID=ourDbUsername;PWD=ourDbPassword;DATABASE=ourDbName;SERVER=ourServerIP',
    'charset' => 'UTF-8'
),

So far so good. If we run our application everything go as expected till a simple GET request fails every time to get details of an object. I can't make the request working even if I remove other requests that are executed before it. Even chaining the request in another way doesn't help. This is the error:

Statement could not be executed (HY000 - 0 - [Microsoft][SQL Server Native Client 11.0]
Connection is busy with results for another command (SQLExecute[0] at /builddir/build/BUILD/php-5.4.16/ext/pdo_odbc/odbc_stmt.c:254) - HY000)

We tried to set the MARS_Connection (described here How to fix native client error 'Connection is busy with results for another command'? on the answer of smozgur). But we don't have such a /etc/odbc.ini file, only a /etc/odbcinst.ini file. So our /etc/odbcinst.ini file is looking like this now:

[ODBC Driver 11 for SQL Server]
Description=Microsoft ODBC Driver 11 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so.2270.0
Threading=1
UsageCount=1
MARS_Connection=yes

Do I miss something in my setup to get this working?


Solution

  • I played around with my db connection and turns out adding 'MARS_Connection=yes;' to my dsn does the job.

    'db' => array(
        'driver' => 'pdo',
        'username' => 'ourDbUsername',
        'password' => 'ourDbPassword',
        'dsn' => 'odbc:DRIVER={SQL Server Native Client 11.0};UID=ourDbUsername;PWD=ourDbPassword;DATABASE=ourDbName;SERVER=ourServerIP;MARS_Connection=yes;',
        'charset' => 'UTF-8'
    ),
    

    Hopefully this can help next searchers!