1

I am using Zend Framework 3 for my project. I would like to use Doctrine with Sql Server 2014. When I use Zend-Db all things are fine but using Doctrine displays me this message:

Fatal error: Invalid handle returned. in C:\Users\root\zendwithsqlserver\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php on line 43

I have done all configurations needed for doctrine First I config my sql server database credentials in config/autoload/local like this:

<?php 
use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as PDOSqlsrvDriver;
return array(
'doctrine' => [
    'connection' => [
        'orm_default' => [
            'driverClass' => PDOSqlsrvDriver::class,
            'params' => [
                'host'     => 'localhost',
                'user'     => 'sa',
                'password' => 'mypassword',
                'dbname'   => 'blog',
            ]
        ],
    ],
],
);

To finish in my module.config.php file located in module/Application/module/ I add the doctrine code to permit it to know where are situated my entities .

'doctrine' => [
    'driver' => [
        __NAMESPACE__ . '_driver' => [
            'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
            'cache' => 'array',
            'paths' => [__DIR__ . '/../src/Entity']
        ],
        'orm_default' => [
            'drivers' => [
                __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
            ]
        ]
    ]
]

I would like to know how can I fix this error?:

Fatal error: Invalid handle returned. in C:\Users\root\zendwithsqlserver\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php on line 43

Any idea or suggestion is welcome, thanks in advance.

SANDWIDI
  • 27
  • 11

1 Answers1

0

Please change the local.php as below code.

<?php
use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver;

return [
   'doctrine' => [
       'connection' => [
           'orm_default' => [
               'driverClass' => SQLSrvDriver::class,
               'params' => [
                   'host'     => 'USER-PC\MYINSTANCE',                    
                   'user'     => 'sa',
                   'password' => 'mypassword',
                   'dbname'   => 'blog',
                   'port'     => '49166'
               ]
           ],            
       ],        
   ],
];

Please refer this link to find the mssql port number : Identify Port used by SQL Server Database Engine Using SQL Server Configuration Manager

Kushal
  • 2,605
  • 4
  • 22
  • 23