SQL Server Stored procedure aborting when called from php

Graham

I have spent hours trying to get to the bottom of this and it is driving me la la.

I have a simple stored procedure that just inputs 10,000 rows into a table. This is done because it takes long enough to prove the point (about 12 seconds).

create table lala (id int not null identity(1,1), txt varchar(100))
go
CREATE PROCEDURE lalatest
AS
BEGIN
    DECLARE @x int;
    SET @x = 10000;
    WHILE @x > 0
    BEGIN
        INSERT INTO lala (txt) VALUES ('blah ' + CAST(@x AS varchar(10)));
        SET @x = @x - 1;
    END;
END;

When I run the stored procedure from within SQL Server Management Studio, 10,000 rows are inserted into the table.

When I run it from php it just aborts after about 150 rows (the number of rows varies, suggesting a timeout issue) with no error messages or any indication that it has finished early

The remote query timeout setting is set to the default of 600 seconds, so its not that.

The php:

$sql = "exec lalatest";
sqlsrv_query($cn, $sql);

I have tried specifying a timeout value (which should be indefinite by default anyway) on the sqlsrv_query line and it made no difference.

I'm using php 5.6.7

and Microsoft SQL Server 2012 (SP3) (KB3072779) - 11.0.6020.0 (X64) Oct 20 2015 15:36:27 Standard Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1) (Hypervisor)

I have all errors and warnings turned on

Anyone got any ideas as to what I need to do to make this work?

Graham

Would you believe it, I have made it work. I added SET NOCOUNT ON as the first line in the stored procedure and now it works from php as well.

Looks like having the rows affected info throws the php sqlsrv driver a wobbly. Strange how it only does it after a certain time (about a second), perhaps something to do with when the message buffer is flushed or something. Yes, I'm guessing, but this has solved the problem, so I'm happy.

CREATE PROCEDURE lalatest
AS
BEGIN
    SET NOCOUNT ON; -- must be added so that it will run from php

    DECLARE @x int;
    SET @x = 10000;
    WHILE @x > 0
    BEGIN
        INSERT INTO lala (txt) VALUES ('blah ' + CAST(@x AS varchar(10)));
        SET @x = @x - 1;
    END;
END;

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

MS SQL Server procedure from php fails with 500 when returning query is not empty

분류에서Dev

Converting Stored Procedure into a query (SQL Server Compact)?

분류에서Dev

Varchar value not passing into SQL Server stored procedure

분류에서Dev

SQL server create stored procedure syntax error

분류에서Dev

how to secure a valuable stored procedure in sql server

분류에서Dev

Call stored procedure from PL/SQL Job

분류에서Dev

Return result set from SQL Server stored procedure to vb.net

분류에서Dev

Emailing from SQL Server stored procedure with set-based logic, avoiding cursors

분류에서Dev

SQL server stored procedure issue in via with c#

분류에서Dev

SQL Server : stored procedure many-to-many table query

분류에서Dev

How to pass schema as parameter to a stored procedure in sql server?

분류에서Dev

Executing Sql Server Stored Procedure and getting OUTPUT INSERTED value

분류에서Dev

SQL Server: EXECUTE AS clause of stored procedure not granting sysadmin permissions

분류에서Dev

How to parse a VARCHAR passed to a stored procedure in SQL Server?

분류에서Dev

How can I back up a stored procedure in SQL Server?

분류에서Dev

Nested stored procedure in SQL

분류에서Dev

Return rowcount from stored procedure T-SQL

분류에서Dev

SQL Stored Procedure Insert All Dates From Current Month Not In

분류에서Dev

Stored Procedure Call from Lightswitch

분류에서Dev

how to split a xml format data into row column format in sql server 2008 using stored procedure

분류에서Dev

SQL Server 2008 R2 - Running a Stored Procedure against Linked Servers

분류에서Dev

SQL Server CLR Library Stored Procedure static object instantiated more than once

분류에서Dev

How I do know if SQL Server Stored Procedure that performs an Update worked?

분류에서Dev

SQL Stored Procedure Get Distinct and Update

분류에서Dev

PL/SQL Stored Procedure - IF THEN ELSE condition

분류에서Dev

SQL stored procedure: how to concatenate parameter value?

분류에서Dev

SQL Stored procedure does not enter IF and CASE condition

분류에서Dev

How to efficiently check stored procedure for existence in PHP

분류에서Dev

PHP with stored procedure - cursor output in Oracle

Related 관련 기사

  1. 1

    MS SQL Server procedure from php fails with 500 when returning query is not empty

  2. 2

    Converting Stored Procedure into a query (SQL Server Compact)?

  3. 3

    Varchar value not passing into SQL Server stored procedure

  4. 4

    SQL server create stored procedure syntax error

  5. 5

    how to secure a valuable stored procedure in sql server

  6. 6

    Call stored procedure from PL/SQL Job

  7. 7

    Return result set from SQL Server stored procedure to vb.net

  8. 8

    Emailing from SQL Server stored procedure with set-based logic, avoiding cursors

  9. 9

    SQL server stored procedure issue in via with c#

  10. 10

    SQL Server : stored procedure many-to-many table query

  11. 11

    How to pass schema as parameter to a stored procedure in sql server?

  12. 12

    Executing Sql Server Stored Procedure and getting OUTPUT INSERTED value

  13. 13

    SQL Server: EXECUTE AS clause of stored procedure not granting sysadmin permissions

  14. 14

    How to parse a VARCHAR passed to a stored procedure in SQL Server?

  15. 15

    How can I back up a stored procedure in SQL Server?

  16. 16

    Nested stored procedure in SQL

  17. 17

    Return rowcount from stored procedure T-SQL

  18. 18

    SQL Stored Procedure Insert All Dates From Current Month Not In

  19. 19

    Stored Procedure Call from Lightswitch

  20. 20

    how to split a xml format data into row column format in sql server 2008 using stored procedure

  21. 21

    SQL Server 2008 R2 - Running a Stored Procedure against Linked Servers

  22. 22

    SQL Server CLR Library Stored Procedure static object instantiated more than once

  23. 23

    How I do know if SQL Server Stored Procedure that performs an Update worked?

  24. 24

    SQL Stored Procedure Get Distinct and Update

  25. 25

    PL/SQL Stored Procedure - IF THEN ELSE condition

  26. 26

    SQL stored procedure: how to concatenate parameter value?

  27. 27

    SQL Stored procedure does not enter IF and CASE condition

  28. 28

    How to efficiently check stored procedure for existence in PHP

  29. 29

    PHP with stored procedure - cursor output in Oracle

뜨겁다태그

보관