我们已经使用 Doctrine2 编写了一个应用程序,它在与 MySQL 或 Postgres 数据库一起使用时效果很好。
我们现在使用 PDO Driver DBLib 将应用程序连接到 SQL Server 2008 数据库它使用 SQL Server 和 Sybase 共享的 TDS(表格数据流协议(protocol))的 FreeTDS
实现。
在对 Doctrine SQLServerPlatform
和我们的 MSSQL 驱动程序包进行一些调整之后,初始模式创建、事务和 INSERT
到表中工作正常。
但是在选择数据的时候,我们会遇到如下错误:
General error: 20019 Attempt to initiate a new Adaptive Server operation with results pending
经过大量谷歌搜索后,我找到了 this detail in the FAQ of FreeTDS :
If you are accustomed to programming with other database servers, you may be surprised when you first encounter this aspect of the TDS protocol. [...]
The server requires the client either to read all the results from a query, or to indicate that no further rows are desired i.e., to issue a cancellation. Until one of those two things happens, the server will not accept new queries on that connection. It will complain about "pending results".
所以出现错误信息的原因是因为某些原因,Doctrine (DBAL->PDO->FreeTDS) 没有从连接缓冲区中读取所有的结果行,服务器/库不允许应用程序发出新的 exec()
/execute()
直到读取所有行。
- 我的理解是否正确,
$doctrinequery->getResults()
在返回之前获取所有结果? - 我的理解是否正确,
$entity->getLinkedEntity()
(即$user->getGroupNames()
)在返回之前获取所有结果? - 您将如何解决问题的确切位置?
堆栈跟踪对我们没有任何帮助,代码库已经增长。 - 是否还有其他人遇到过这个问题并可以分享一些见解?
- 有没有我们可以用来将 Doctrine 连接到 MSSQL 而不会遇到这个问题的替代方法?
最佳答案
我在 PDO 驱动程序 DBLib 和事务方面遇到了类似的问题。我是这样修复的:
$this->_db->beginTransaction();
$st = $this->_db->prepare("StoredProcedure ?");
$st->execute(array($data));
$results= $st->fetchAll();
$st->closeCursor();
// more stuff
$this->_db->commit();
closeCursor()
解决了我的问题:http://php.net/manual/en/pdostatement.closecursor.php
关于php - 选择 Doctrine 和 MS SQL 2008 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13280717/