msphpsql: Fatal error: Invalid handle returned - for all connections if one fails

After one connection using pdo_sqlsrv v4.0.8629.2 fails, for example because of incorrect user/pass, All the other connections also are failing with PHP Fatal error: Invalid handle returned.

Environment: Win10, Apache/2.4.23 (Win64) OpenSSL/1.0.2h PHP/7.0.9 using php_pdo_sqlsrv_7_ts_x64.dll.

Reproducing: 2 php scripts that are creating DB connections using php, like: file1.php: <?php try{ $dbconnection = new PDO('sqlsrv:Server=localhost;Database=cdr41', 'existinguser', 'existingpassword'); echo 'OK'; }catch(PDOException $e){ echo $e->getMessage(); } ?>

file2.php: <?php try{ $dbconnection = new PDO('sqlsrv:Server=localhost;Database=cdr41', 'fakeuser', 'fakepassword'); echo 'OK'; }catch(PDOException $e){ echo $e->getMessage(); } ?>

I can run file1.php multiple times without any problems, but after running even once file2.php, first time file2.php generates and exception, like it should, but after that file1.php and file2.php are failing with Fatal error: Invalid handle returned.

When switching back to 32bit apache + php + pdo SQL driver 3.2 all works as expected.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 23 (7 by maintainers)

Most upvoted comments

@ethan-tr , in your config/database.php add 'pooling' => false, to your database parameters, as follow:

'connections' => [
        'sqlsrv' => [
            'driver'   => 'sqlsrv',
            'host'     => env( 'DB_HOST' ),
            'port'     => env( 'DB_PORT', 1433 ),
            'database' => env( 'DB_DATABASE' ),
            'username' => env( 'DB_USERNAME' ),
            'password' => env( 'DB_PASSWORD' ),
            'prefix'   => '',
            'charset'  => 'UTF-8',
            'appname'  => 'App name',
            'pooling'  => false,
        ],
],

@lancepioch @all We are able to repro this bug in our lab. We are fixing it as we talk and will aim to fix it in our next release. Our next release should be out very soon.

@ethanhann-tr @super-vip @eziitiss @mlhkr We are looking into this and will aim to fix this asap. Stay tuned 😃

@meet-bhagdev This issue is really annoying. If you already have a fix, please consider doing a release even if we have to wait longer for other fixes.