fabionvs
fabionvs

Reputation: 197

PHP Doctrine with SQL Server Always On

I am developing an application using Symfony 3 (php 7.1) with SQL Server database with AlwaysOn. AlwaysOn is a SQL server support for high-availability and disaster recovery, and Doctrine 2 is not working well with this paradigm.

I've developed a CRUD to test it for the infrastructure section at my job that implemented this database. At the first time, it was working correctly and persisting ok. But, when they change the instance for another one, like when happens if the first one stops working, automatically go to the other instance with the same database structure and data. When it happens I receive an error message from doctrine:

Fatal error: Invalid handle returned. in C:\xampp\htdocs\testesql\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php on line 43

It looks like Doctrine caches something that is not working with this paradigm of database. I am using Microsoft SQL Server driver (pdo_sqlsrv). Could someone help me? I would be glad.

Upvotes: 0

Views: 1784

Answers (1)

fabionvs
fabionvs

Reputation: 197

Problem solved! It is very hard to work with SQL Server Always On considering it is a new tecnology and PHP 7.1 is too. (08/06/17)

I solved the problem changing symfony doctrine driver from "pdo_sqlsrv" to just "sqlsrv" follwing Doctrine 2 Documentation infos.

If anyone has a problem with SQL Server Always On using PHP, remember:

  • It is only possible to login different instances with Windows User (AD or LDAP). You would not be able to login using DB user and pass using different instances.

  • To login in SQL Server Always On to make it work correctly, you have to login in the database using Apache authentication.

Upvotes: 1

Related Questions