1

So I'm confident that the stored procedure works, I've tested it in SQL Server Management Studio just fine and it runs in other service instances. The query used to run this SP follows;

exec sp_getAgentCommissionDetails_v3 201000023762230, 5

So it runs fine on SSMS and under the old MSSQL driver. But I run the query with SQLSRV like so;

function mssql_query($string, $linkID = null, $batch = 0) {
    if (!$linkID) {
        global $dbhandle;

        $linkID = $dbhandle;
    }

    // SQLSRV_CURSOR_KEYSET ensures mssql_num_rows() works in most cases. Default scrollablility does not support this.
    return sqlsrv_query($linkID, $string, array(), array("Scrollable" => SQLSRV_CURSOR_KEYSET));
}

The function is named mssql_query because we're updating an old system from MSSQL to SQLSRV, but we're working with an extremely messy old system. So rather than trying to refactor it we're overwriting the MSSQL_query function (having disabled the mssql extension) with one that uses SQLSRV. $dbhandle is our SQLSRV connection resource. Other queries run just fine using this method.

So my question- is there any reason the query to run a stored procedure would not run under this SQLSRV function?

Couple notes on my troubleshooting;

I'm aware SQLSRV and PDO have a specific method to run stored procedures. Using that is not an option due to the massive codebase that uses the method above in various places and because we haven't got the man hours to refactor every page.

I pulled up SQLSRV_errors() and it returned 'Executing SQL directly; no cursor'. After a bit of research this seems to be a bug in the driver that returns this generic error message instead of a more specific useful one, so it can mean very many things. There are no cursors or loops involved in the stored procedure.

4

1 回答 1

0

找到了解决方案。SQLSRV 似乎默认将警告视为错误。通过连接文件中的配置更改修复了此问题;

sqlsrv_configure("WarningsReturnAsErrors",0);

它现在运行良好。

于 2013-07-12T10:02:01.943 回答